Revision 9b136840 lib/net.c

View differences:

lib/net.c
8 8
  [NET_IP6] = sizeof(net_addr_ip6),
9 9
  [NET_VPN4] = sizeof(net_addr_vpn4),
10 10
  [NET_VPN6] = sizeof(net_addr_vpn6)
11
}
11
};
12 12

  
13
char *
13
int
14 14
net_format(const net_addr *N, char *buf, int buflen)
15 15
{
16 16
  net_addr_union *n = (void *) N;
......
27 27
  case NET_VPN6:
28 28
    return bsnprintf(buf, buflen, "%u:%u %I/%d", (u32) (n->vpn6.rd >> 32), (u32) n->vpn6.rd, n->vpn6.prefix, n->vpn6.pxlen);
29 29
  }
30

  
31
  return 0;
32
}
33

  
34

  
35
ip_addr
36
net_pxmask(const net_addr *a)
37
{
38
  switch (a->type)
39
  {
40
  case NET_IP4:
41
  case NET_VPN4:
42
    return ipa_from_ip4(ip4_mkmask(net4_pxlen(a)));
43

  
44
  case NET_IP6:
45
  case NET_VPN6:
46
    return ipa_from_ip6(ip6_mkmask(net6_pxlen(a)));
47

  
48
  default:
49
    return IPA_NONE;
50
  }
51
}
52

  
53

  
54
static inline int net_validate_ip4(const net_addr_ip4 *n)
55
{
56
  return (n->pxlen <= IP4_MAX_PREFIX_LENGTH) &&
57
    ip4_zero(ip4_and(n->prefix, ip4_not(ip4_mkmask(n->pxlen))));
58
}
59

  
60
static inline int net_validate_ip6(const net_addr_ip6 *n)
61
{
62
  return (n->pxlen <= IP6_MAX_PREFIX_LENGTH) &&
63
    ip6_zero(ip6_and(n->prefix, ip6_not(ip6_mkmask(n->pxlen))));
64
}
65

  
66
int
67
net_validate(const net_addr *N)
68
{
69
  switch (a->type)
70
  {
71
  case NET_IP4:
72
  case NET_VPN4:
73
    return net_validate_ip4((net_addr_ip4 *) N);
74

  
75
  case NET_IP6:
76
  case NET_VPN6:
77
    return net_validate_ip6((net_addr_ip6 *) N);
78

  
79
  default:
80
    return 0;
81
  }
30 82
}
31 83

  
32 84
int
......
42 94

  
43 95
  case NET_IP6:
44 96
  case NET_VPN6:
45
    return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(n->ip6.prefix);
97
    return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix);
46 98
  }
99

  
100
  return 0;
47 101
}

Also available in: Unified diff