Statistics
| Branch: | Revision:

iof-bird-daemon / lib / net.c @ fe9f1a6d

History | View | Annotate | Download (1.2 KB)

1

    
2
#include "nest/bird.h"
3
#include "lib/ip.h"
4
#include "lib/net.h"
5

    
6
const u16 net_addr_length[] = {
7
  [NET_IP4] = sizeof(net_addr_ip4),
8
  [NET_IP6] = sizeof(net_addr_ip6),
9
  [NET_VPN4] = sizeof(net_addr_vpn4),
10
  [NET_VPN6] = sizeof(net_addr_vpn6)
11
}
12

    
13
char *
14
net_format(const net_addr *N, char *buf, int buflen)
15
{
16
  net_addr_union *n = (void *) N;
17

    
18
  /* FIXME: quick hack */
19
  switch (n->n.type)
20
  {
21
  case NET_IP4:
22
    return bsnprintf(buf, buflen, "%I/%d", n->ip4.prefix, n->ip4.pxlen);
23
  case NET_IP6:
24
    return bsnprintf(buf, buflen, "%I/%d", n->ip6.prefix, n->ip6.pxlen);
25
  case NET_VPN4:
26
    return bsnprintf(buf, buflen, "%u:%u %I/%d", (u32) (n->vpn4.rd >> 32), (u32) n->vpn4.rd, n->vpn4.prefix, n->vpn4.pxlen);
27
  case NET_VPN6:
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
  }
30
}
31

    
32
int
33
net_classify(const net_addr *N)
34
{
35
  net_addr_union *n = (void *) N;
36

    
37
  switch (n->n.type)
38
  {
39
  case NET_IP4:
40
  case NET_VPN4:
41
    return ip4_zero(n->ip4.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip4_classify(n->ip4.prefix);
42

    
43
  case NET_IP6:
44
  case NET_VPN6:
45
    return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(n->ip6.prefix);
46
  }
47
}