--- embedaddon/quagga/zebra/rt_netlink.c 2012/10/09 09:22:29 1.1.1.2 +++ embedaddon/quagga/zebra/rt_netlink.c 2013/07/21 23:54:41 1.1.1.3 @@ -43,7 +43,7 @@ #include "zebra/interface.h" #include "zebra/debug.h" -#define NL_PKT_BUF_SIZE 4096 +#include "rt_netlink.h" /* Socket interface to kernel */ struct nlsock @@ -68,20 +68,6 @@ static const struct message nlmsg_str[] = { {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_privs_t zserv_privs; @@ -1236,7 +1222,7 @@ netlink_route_read (void) /* Utility function comes from iproute2. Authors: Alexey Kuznetsov, */ -static int +int addattr_l (struct nlmsghdr *n, int maxlen, int type, void *data, int alen) { int len; @@ -1256,7 +1242,7 @@ addattr_l (struct nlmsghdr *n, int maxlen, int type, v return 0; } -static int +int rta_addattr_l (struct rtattr *rta, int maxlen, int type, void *data, int alen) { int len; @@ -1278,7 +1264,7 @@ rta_addattr_l (struct rtattr *rta, int maxlen, int typ /* Utility function comes from iproute2. Authors: Alexey Kuznetsov, */ -static int +int addattr32 (struct nlmsghdr *n, int maxlen, int type, int data) { int len; @@ -1368,7 +1354,7 @@ netlink_route (int cmd, int family, void *dest, int le char buf[NL_PKT_BUF_SIZE]; } req; - memset (&req, 0, sizeof req); + memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); bytelen = (family == AF_INET ? 4 : 16); @@ -1443,7 +1429,7 @@ netlink_route_multipath (int cmd, struct prefix *p, st char buf[NL_PKT_BUF_SIZE]; } req; - memset (&req, 0, sizeof req); + memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); bytelen = (family == AF_INET ? 4 : 16); @@ -1515,7 +1501,7 @@ netlink_route_multipath (int cmd, struct prefix *p, st inet_ntoa (p->u.prefix4), #endif /* HAVE_IPV6 */ - p->prefixlen, nexthop_types_desc[nexthop->rtype]); + p->prefixlen, nexthop_type_to_str (nexthop->rtype)); } if (nexthop->rtype == NEXTHOP_TYPE_IPV4 @@ -1580,7 +1566,7 @@ netlink_route_multipath (int cmd, struct prefix *p, st #else inet_ntoa (p->u.prefix4), #endif /* HAVE_IPV6 */ - p->prefixlen, nexthop_types_desc[nexthop->type]); + p->prefixlen, nexthop_type_to_str (nexthop->type)); } if (nexthop->type == NEXTHOP_TYPE_IPV4 @@ -1687,7 +1673,7 @@ netlink_route_multipath (int cmd, struct prefix *p, st #else inet_ntoa (p->u.prefix4), #endif /* HAVE_IPV6 */ - p->prefixlen, nexthop_types_desc[nexthop->rtype]); + p->prefixlen, nexthop_type_to_str (nexthop->rtype)); } if (nexthop->rtype == NEXTHOP_TYPE_IPV4 || nexthop->rtype == NEXTHOP_TYPE_IPV4_IFINDEX) @@ -1761,7 +1747,7 @@ netlink_route_multipath (int cmd, struct prefix *p, st #else inet_ntoa (p->u.prefix4), #endif /* HAVE_IPV6 */ - p->prefixlen, nexthop_types_desc[nexthop->type]); + p->prefixlen, nexthop_type_to_str (nexthop->type)); } if (nexthop->type == NEXTHOP_TYPE_IPV4 || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) @@ -1903,7 +1889,7 @@ netlink_address (int cmd, int family, struct interface } req; p = ifc->address; - memset (&req, 0, sizeof req); + memset (&req, 0, sizeof req - NL_PKT_BUF_SIZE); bytelen = (family == AF_INET ? 4 : 16); @@ -1985,7 +1971,7 @@ static void netlink_install_filter (int sock, __u32 pi }; struct sock_fprog prog = { - .len = sizeof(filter) / sizeof(filter[0]), + .len = array_size(filter), .filter = filter, }; @@ -2022,4 +2008,22 @@ kernel_init (void) netlink_install_filter (netlink.sock, netlink_cmd.snl.nl_pid); 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); }