version 1.1.1.2, 2012/10/09 09:22:29
|
version 1.1.1.3, 2013/07/21 23:54:41
|
Line 43
|
Line 43
|
#include "zebra/interface.h" |
#include "zebra/interface.h" |
#include "zebra/debug.h" |
#include "zebra/debug.h" |
|
|
#define NL_PKT_BUF_SIZE 4096 | #include "rt_netlink.h" |
|
|
/* Socket interface to kernel */ |
/* Socket interface to kernel */ |
struct nlsock |
struct nlsock |
Line 68 static const struct message nlmsg_str[] = {
|
Line 68 static const struct message nlmsg_str[] = {
|
{0, NULL} |
{0, NULL} |
}; |
}; |
|
|
static const char *nexthop_types_desc[] = |
|
{ |
|
"none", |
|
"Directly connected", |
|
"Interface route", |
|
"IPv4 nexthop", |
|
"IPv4 nexthop with ifindex", |
|
"IPv4 nexthop with ifname", |
|
"IPv6 nexthop", |
|
"IPv6 nexthop with ifindex", |
|
"IPv6 nexthop with ifname", |
|
"Null0 nexthop", |
|
}; |
|
|
|
extern struct zebra_t zebrad; |
extern struct zebra_t zebrad; |
|
|
extern struct zebra_privs_t zserv_privs; |
extern struct zebra_privs_t zserv_privs; |
Line 1236 netlink_route_read (void)
|
Line 1222 netlink_route_read (void)
|
|
|
/* Utility function comes from iproute2. |
/* Utility function comes from iproute2. |
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */ |
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */ |
static int | int |
addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen) |
addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen) |
{ |
{ |
int len; |
int len; |
Line 1256 addattr_l (struct nlmsghdr *n, int maxlen, int type, v
|
Line 1242 addattr_l (struct nlmsghdr *n, int maxlen, int type, v
|
return 0; |
return 0; |
} |
} |
|
|
static int | int |
rta_addattr_l (struct rtattr *rta, int maxlen, int type, void *data, int alen) |
rta_addattr_l (struct rtattr *rta, int maxlen, int type, void *data, int alen) |
{ |
{ |
int len; |
int len; |
Line 1278 rta_addattr_l (struct rtattr *rta, int maxlen, int typ
|
Line 1264 rta_addattr_l (struct rtattr *rta, int maxlen, int typ
|
|
|
/* Utility function comes from iproute2. |
/* Utility function comes from iproute2. |
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */ |
Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> */ |
static int | int |
addattr32 (struct nlmsghdr *n, int maxlen, int type, int data) |
addattr32 (struct nlmsghdr *n, int maxlen, int type, int data) |
{ |
{ |
int len; |
int len; |
Line 1368 netlink_route (int cmd, int family, void *dest, int le
|
Line 1354 netlink_route (int cmd, int family, void *dest, int le
|
char buf[NL_PKT_BUF_SIZE]; |
char buf[NL_PKT_BUF_SIZE]; |
} req; |
} req; |
|
|
memset (&req, 0, sizeof req); | memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); |
|
|
bytelen = (family == AF_INET ? 4 : 16); |
bytelen = (family == AF_INET ? 4 : 16); |
|
|
Line 1443 netlink_route_multipath (int cmd, struct prefix *p, st
|
Line 1429 netlink_route_multipath (int cmd, struct prefix *p, st
|
char buf[NL_PKT_BUF_SIZE]; |
char buf[NL_PKT_BUF_SIZE]; |
} req; |
} req; |
|
|
memset (&req, 0, sizeof req); | memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); |
|
|
bytelen = (family == AF_INET ? 4 : 16); |
bytelen = (family == AF_INET ? 4 : 16); |
|
|
Line 1515 netlink_route_multipath (int cmd, struct prefix *p, st
|
Line 1501 netlink_route_multipath (int cmd, struct prefix *p, st
|
inet_ntoa (p->u.prefix4), |
inet_ntoa (p->u.prefix4), |
#endif /* HAVE_IPV6 */ |
#endif /* HAVE_IPV6 */ |
|
|
p->prefixlen, nexthop_types_desc[nexthop->rtype]); | p->prefixlen, nexthop_type_to_str (nexthop->rtype)); |
} |
} |
|
|
if (nexthop->rtype == NEXTHOP_TYPE_IPV4 |
if (nexthop->rtype == NEXTHOP_TYPE_IPV4 |
Line 1580 netlink_route_multipath (int cmd, struct prefix *p, st
|
Line 1566 netlink_route_multipath (int cmd, struct prefix *p, st
|
#else |
#else |
inet_ntoa (p->u.prefix4), |
inet_ntoa (p->u.prefix4), |
#endif /* HAVE_IPV6 */ |
#endif /* HAVE_IPV6 */ |
p->prefixlen, nexthop_types_desc[nexthop->type]); | p->prefixlen, nexthop_type_to_str (nexthop->type)); |
} |
} |
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4 |
if (nexthop->type == NEXTHOP_TYPE_IPV4 |
Line 1687 netlink_route_multipath (int cmd, struct prefix *p, st
|
Line 1673 netlink_route_multipath (int cmd, struct prefix *p, st
|
#else |
#else |
inet_ntoa (p->u.prefix4), |
inet_ntoa (p->u.prefix4), |
#endif /* HAVE_IPV6 */ |
#endif /* HAVE_IPV6 */ |
p->prefixlen, nexthop_types_desc[nexthop->rtype]); | p->prefixlen, nexthop_type_to_str (nexthop->rtype)); |
} |
} |
if (nexthop->rtype == NEXTHOP_TYPE_IPV4 |
if (nexthop->rtype == NEXTHOP_TYPE_IPV4 |
|| nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX) |
|| nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX) |
Line 1761 netlink_route_multipath (int cmd, struct prefix *p, st
|
Line 1747 netlink_route_multipath (int cmd, struct prefix *p, st
|
#else |
#else |
inet_ntoa (p->u.prefix4), |
inet_ntoa (p->u.prefix4), |
#endif /* HAVE_IPV6 */ |
#endif /* HAVE_IPV6 */ |
p->prefixlen, nexthop_types_desc[nexthop->type]); | p->prefixlen, nexthop_type_to_str (nexthop->type)); |
} |
} |
if (nexthop->type == NEXTHOP_TYPE_IPV4 |
if (nexthop->type == NEXTHOP_TYPE_IPV4 |
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) |
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) |
Line 1903 netlink_address (int cmd, int family, struct interface
|
Line 1889 netlink_address (int cmd, int family, struct interface
|
} req; |
} req; |
|
|
p = ifc->address; |
p = ifc->address; |
memset (&req, 0, sizeof req); | memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); |
|
|
bytelen = (family == AF_INET ? 4 : 16); |
bytelen = (family == AF_INET ? 4 : 16); |
|
|
Line 1985 static void netlink_install_filter (int sock, __u32 pi
|
Line 1971 static void netlink_install_filter (int sock, __u32 pi
|
}; |
}; |
|
|
struct sock_fprog prog = { |
struct sock_fprog prog = { |
.len = sizeof(filter) / sizeof(filter[0]), | .len = array_size(filter), |
.filter = filter, |
.filter = filter, |
}; |
}; |
|
|
Line 2022 kernel_init (void)
|
Line 2008 kernel_init (void)
|
netlink_install_filter (netlink.sock, netlink_cmd.snl.nl_pid); |
netlink_install_filter (netlink.sock, netlink_cmd.snl.nl_pid); |
thread_add_read (zebrad.master, kernel_read, NULL, netlink.sock); |
thread_add_read (zebrad.master, kernel_read, NULL, netlink.sock); |
} |
} |
|
} |
|
|
|
/* |
|
* nl_msg_type_to_str |
|
*/ |
|
const char * |
|
nl_msg_type_to_str (uint16_t msg_type) |
|
{ |
|
return lookup (nlmsg_str, msg_type); |
|
} |
|
|
|
/* |
|
* nl_rtproto_to_str |
|
*/ |
|
const char * |
|
nl_rtproto_to_str (u_char rtproto) |
|
{ |
|
return lookup (rtproto_str, rtproto); |
} |
} |