From 55196042ac8def6f0057039017eb6a400d7f73fb Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Wed, 17 May 2006 15:04:59 +0000 Subject: [debug] Improve zebra kernel socket debug message to include IP addresses. 2006-05-17 Andrew J. Schorr * kernel_socket.c: (ifam_read_mesg) Improve debug message to show the IP address. --- zebra/kernel_socket.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 9764cbb3..bd4d9c4b 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -510,9 +510,46 @@ ifam_read_mesg (struct ifa_msghdr *ifm, RTA_ADDR_GET (brd, RTA_BRD, ifm->ifam_addrs, pnt); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x", - __func__, ifm->ifam_index, - (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs); + { + switch (sockunion_family(addr)) + { + case AF_INET: + { + char buf[2][INET_ADDRSTRLEN]; + zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, " + "addr %s/%d broad %s", + __func__, ifm->ifam_index, + (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs, + inet_ntop(AF_INET,&addr->sin.sin_addr, + buf[0],sizeof(buf[0])), + ip_masklen(mask->sin.sin_addr), + inet_ntop(AF_INET,&brd->sin.sin_addr, + buf[1],sizeof(buf[1]))); + } + break; +#ifdef HAVE_IPV6 + case AF_INET6: + { + char buf[2][INET6_ADDRSTRLEN]; + zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, " + "addr %s/%d broad %s", + __func__, ifm->ifam_index, + (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs, + inet_ntop(AF_INET6,&addr->sin6.sin6_addr, + buf[0],sizeof(buf[0])), + ip6_masklen(mask->sin6.sin6_addr), + inet_ntop(AF_INET6,&brd->sin6.sin6_addr, + buf[1],sizeof(buf[1]))); + } + break; +#endif /* HAVE_IPV6 */ + default: + zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x", + __func__, ifm->ifam_index, + (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs); + break; + } + } /* Assert read up end point matches to end point */ if (pnt != end) -- cgit v1.2.3 From 9458b8191563eb5569f341172484a234ef2f743e Mon Sep 17 00:00:00 2001 From: Greg Troxel Date: Wed, 13 Sep 2006 12:13:08 +0000 Subject: 2006-09-13 Tom Everett * kernel_socket.c (rtm_type_str): ifdef RTM_OLD{ADD,DEL} to compile on systems that no longer define them. --- zebra/kernel_socket.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index bd4d9c4b..f384e979 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -136,8 +136,12 @@ struct message rtm_type_str[] = {RTM_REDIRECT, "RTM_REDIRECT"}, {RTM_MISS, "RTM_MISS"}, {RTM_LOCK, "RTM_LOCK"}, +#ifdef OLDADD {RTM_OLDADD, "RTM_OLDADD"}, +#endif /* RTM_OLDADD */ +#ifdef RTM_OLDDEL {RTM_OLDDEL, "RTM_OLDDEL"}, +#endif /* RTM_OLDDEL */ {RTM_RESOLVE, "RTM_RESOLVE"}, {RTM_NEWADDR, "RTM_NEWADDR"}, {RTM_DELADDR, "RTM_DELADDR"}, -- cgit v1.2.3 From e4529636b77124285cca96a62799d0ff6a7addeb Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 12 Dec 2006 19:18:21 +0000 Subject: [PtP over ethernet] New peer flag allows much more addressing flexibility 2006-12-12 Andrew J. Schorr * if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating whether a peer address has been configured. Comment now shows the new interpretation of the destination addr: if ZEBRA_IFA_PEER is set, then it must contain the destination address, otherwise it may contain the broadcast address or be NULL. (CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete macros that were specific to IPv4 and not fully general. (CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag. (CONNECTED_PREFIX) New macro giving the prefix to insert into the RIB: if CONNECTED_PEER, then use the destination (peer) address, else use the address field. (CONNECTED_ID) New macro to come up with an identifying address for the struct connected. * if.c: (if_lookup_address, connected_lookup_address) Streamline logic with new CONNECTED_PREFIX macro. * prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros for better performance than the general prefix_copy function. * zclient.c: (zebra_interface_address_read) For non-null destination addresses, set prefixlen to equal the address prefixlen. This is needed to get the new CONNECTED_PREFIX macro to work properly. * connected.c: (connected_up_ipv4, connected_down_ipv4, connected_up_ipv6, connected_down_ipv6) Simplify logic using the new CONNECTED_PREFIX macro. (connected_add_ipv4) Set prefixlen in destination addresses (required by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead of testing for IFF_POINTOPOINT. Delete invalid warning message. Warn about cases where the ZEBRA_IFA_PEER is set but no destination address has been supplied (and turn off the flag). (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning. Set prefixlen in destination address so CONNECTED_PREFIX will work. * connected.h: (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. * interface.c: (connected_dump_vty) Use CONNECTED_PEER macro to decide whether the destination address is a peer or broadcast address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT). * if_ioctl.c: (if_getaddrs) Instead of setting a peer address only when the IFF_POINTOPOINT is set, we now accept a peer address whenever it is available and not the same as the local address. Otherwise (no peer address assigned), we check for a broadcast address (regardless of the IFF_BROADCAST flag). And must now pass a flags value of ZEBRA_IFA_PEER to connected_add_ipv4 when a peer address is assigned. The same new logic is used with the IPv6 code as well (and we pass the new flags argument to connected_add_ipv6). (if_get_addr) Do not bother to check IFF_POINTOPOINT: just issue the SIOCGIFDSTADDR ioctl and see if we get back a peer address not matching the local address (and set the ZEBRA_IFA_PEER in that case). If there's no peer address, try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set. * if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl without bothering to check the IFF_POINTOPOINT flag. And if no peer address was found, just try the SIOCGLIFBRDADDR ioctl without checking the IFF_BROADCAST flag. Call connected_add_ipv4 and connected_add_ipv6 with appropriate flags. * if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to connected_add_ipv6. * kernel_socket.c: (ifam_read) Must pass new flags argument to connected_add_ipv6. * rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2 to determine local and possible peer address (so there's no longer a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately. Pass new flags argument to connected_add_ipv6. (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast to determine whether the connected destination address is a broadcast address. * bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete) Simplify logic by using new CONNECTED_PREFIX macro. * ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix, ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX macro. * ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX macro, both options collapse into the same code. * ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new CONNECTED_ID macro. (ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX macro. * ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro instead of testing the IFF_POINTOPOINT flag. * ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro instead of testing with if_is_pointopoint. And add commented-out code to implement alternative (in my opinion) more elegant behavior that has no special-case treatment for PtP addresses. (ospf_network_run) Use new CONNECTED_ID macro to simplify logic. * rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID macro to simplify logic. (rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does not give a useful result if prefixlen is 32 (we require a peer address in such cases). * ripd.c: (rip_update_interface) Fix same bug as above. --- zebra/kernel_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index f384e979..ac06566a 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -609,7 +609,7 @@ ifam_read (struct ifa_msghdr *ifam) SET_IN6_LINKLOCAL_IFINDEX (addr.sin6.sin6_addr, 0); if (ifam->ifam_type == RTM_NEWADDR) - connected_add_ipv6 (ifp, + connected_add_ipv6 (ifp, 0, &addr.sin6.sin6_addr, ip6_masklen (mask.sin6.sin6_addr), &brd.sin6.sin6_addr, -- cgit v1.2.3 From 6502208c3217e52e693146e6b72e76fd76982a51 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Tue, 6 Mar 2007 13:43:05 +0000 Subject: [zebra] Fix interface metric bug on BSD 2007-03-06 Paul Jakma * kernel_socket.c: (ifam_read) Do not update interface metric on receipt of NEW/DEL ADDR messages, bogus as: a) some systems dont include iface metric for address events b) we didn't update clients either. Initial diagnosis by Eugene Grosbein. --- zebra/kernel_socket.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index ac06566a..52812367 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -585,8 +585,15 @@ ifam_read (struct ifa_msghdr *ifam) if (ifnlen && strncmp (ifp->name, ifname, INTERFACE_NAMSIZ)) isalias = 1; +#if 0 + /* it might seem cute to grab the interface metric here, however + * we're processing an address update message, and so some systems + * (e.g. FBSD) dont bother to fill in ifam_metric. Disabled, but left + * in deliberately, as comment. + */ ifp->metric = ifam->ifam_metric; - +#endif + /* Add connected address. */ switch (sockunion_family (&addr)) { -- cgit v1.2.3 From 7514fb7739f74311830e9ddd1381d0d228224f61 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Wed, 2 May 2007 16:05:35 +0000 Subject: [zebra] Routemap support on received routes, with 'set src' command (linux) 2007-05-01 David L Stevens * (general) These changes collectively add route-map and prefix-list support to zebra and fix a bug in "show route-map" (with no argument). * doc/main.texi: added route-map, prefix-list, ip protocol and set src documentation * lib/command.h: added PROTOCOL_NODE type * lib/log.c: (proto_name2num) new function, protocol name to number translation. * lib/routemap.c: (vty_show_route_map) fixed "show route-map" without route-map name * lib/routemap.h: added RMAP_ZEBRA type * lib/zebra.h: added proto_name2num() prototype * vtysh/extract.pl.in: added VTYSH_ZEBRA flag for route-map and plist * vtysh/Makefile.am: added zebra_routemap.c * vtysh/vtysh.h: added VTYSH_ZEBRA flag to VTYSH_RMAP * zebra/connected.c: (connected_up_ipv4) added src preference argument to rib_add_ipv4() * zebra/kernel_socket.c: (rtm_read) ditto * zebra/main.c: added prefix list initialization * zebra/Makefile.am: added zebra_routemap.c source file * zebra/rib.h: added generic address union "g_addr" and use in existing places that had an explicit union. Added "src" to struct nexthop. Added preferred src arg to nexthop_ipv4_add and rib_add_ipv4. * zebra/rt_netlink.c: (netlink_routing_table) set preferred source on netlink messages. (netlink_route_change) ditto (netlink_route_multipath) ditto. * zebra/rtread_getmsg.c: (handle_route_entry) added (NULL) src to rib_add_ipv4() call. * zebra/rtread_proc.c: (proc_route_read) ditto * zebra/zebra_rib.c: (nexthop_ipv4_add) add src argument. (nexthop_ipv4_ifindex_add) ditto (rib_add_ipv4) ditto (nexthop_active_check) Add route-map processing. * zebra/zebra_routemap.c: new file for zebra route-map commands. * zebra/zebra_vty.c: (ip_protocol_cmd) Apply route-map to protocol (vty_show_ip_route_detail) added "src" printing (vty_show_ip_route) ditto (show_ip_protocol_cmd) new command, list routemaps. (config_write_protocol) write out routemap protocl config. (zebra_vty_init) Install the new routemap protocol commands. * zebra/zserv.c: (zread_ipv4_add) added (NULL) src arg (zebra_init) init zebra route-maps. * zebra/zserv.h: add zebra_route_map_init --- zebra/kernel_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 52812367..b7c7ccc1 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -775,7 +775,7 @@ rtm_read (struct rt_msghdr *rtm) || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, zebra_flags, - &p, &gate.sin.sin_addr, 0, 0, 0, 0); + &p, &gate.sin.sin_addr, NULL, 0, 0, 0, 0); else rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, zebra_flags, &p, &gate.sin.sin_addr, 0, 0); -- cgit v1.2.3 From 6f0e3f6e17687eb25b7b77c4fdc8324837d4700f Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 10 May 2007 02:38:51 +0000 Subject: [autoconf] bugs 162,303,178: Fix 'present but can not be compiled' warnings 2007-05-09 Paul Jakma * configure.ac: sys/conf.h depends on sys/param.h, at least on FBSD 6.2. (bug #363) Should check for in_pktinfo for IRDP 2006-05-27 Paul Jakma * configure.ac: General cleanup of header and type checks, introducing an internal define, QUAGGA_INCLUDES, to build up a list of stuff to include so as to avoid 'present but cant be compiled' warnings. Misc additional checks of things missing according to autoscan. Add LIBM, for bgpd's use of libm, so as to avoid burdening LIBS, and all the binaries, with libm linkage. Remove the bad practice of using m4 changequote(), just quote the []'s in the case statements properly. This should fix bugs 162, 303 and 178. * */*.{c,h}: Update all HAVE_* to the standard autoconf namespaced HAVE_* defines. I.e. HAVE_SA_LEN -> HAVE_STRUCT_SOCKADDR_SA_LEN, * bgpd/Makefile.am: Add LIBM to bgpd's LDADD, for pow(). --- zebra/kernel_socket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index b7c7ccc1..795ed55f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -56,7 +56,7 @@ extern struct zebra_t zebrad; * Given a pointer (sockaddr or void *), return the number of bytes * taken up by the sockaddr and any padding needed for alignment. */ -#if defined(HAVE_SA_LEN) +#if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) #define SAROUNDUP(X) ROUNDUP(((struct sockaddr *)(X))->sa_len) #elif defined(HAVE_IPV6) /* @@ -76,7 +76,7 @@ extern struct zebra_t zebrad; ROUNDUP(sizeof(struct sockaddr_in)):\ (((struct sockaddr *)(X))->sa_family == AF_LINK ? \ ROUNDUP(sizeof(struct sockaddr_dl)) : sizeof(struct sockaddr))) -#endif /* HAVE_SA_LEN */ +#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ /* We use an additional pointer in following, pdest, rather than (DEST) * directly, because gcc will warn if the macro is expanded and DEST is NULL, @@ -902,7 +902,7 @@ rtm_write (int message, msg.rtm.rtm_flags |= RTF_REJECT; -#ifdef HAVE_SIN_LEN +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN #define SOCKADDRSET(X,R) \ if (msg.rtm.rtm_addrs & (R)) \ { \ @@ -918,7 +918,7 @@ rtm_write (int message, memcpy (pnt, (caddr_t)(X), len); \ pnt += len; \ } -#endif /* HAVE_SIN_LEN */ +#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ pnt = (caddr_t) msg.buf; -- cgit v1.2.3 From 7ab62c5319bd86a3cfda32351bc4103cf9517f26 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 17 May 2007 15:00:41 +0000 Subject: [PtP] Fix BSD problems with PtP interfaces: must treat RTA_BRD as peer address 2007-05-17 Andrew J. Schorr * kernel_socket.c: (ifam_read_mesg) Grab RTA_DST and RTA_GATEWAY addresses from the message (if present, which seems unlikely on current BSD platforms), and show them in the debug messages. Also, add ifam_flags to the debug messages. (ifam_read) If the interface is point-to-point, then the RTA_BRD address should be treated as a peer address. --- zebra/kernel_socket.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 795ed55f..7bc1b0f9 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -494,6 +494,8 @@ ifam_read_mesg (struct ifa_msghdr *ifm, short *ifnlen) { caddr_t pnt, end; + union sockunion dst; + union sockunion gateway; pnt = (caddr_t)(ifm + 1); end = ((caddr_t)ifm) + ifm->ifam_msglen; @@ -502,10 +504,12 @@ ifam_read_mesg (struct ifa_msghdr *ifm, memset (mask, 0, sizeof (union sockunion)); memset (addr, 0, sizeof (union sockunion)); memset (brd, 0, sizeof (union sockunion)); + memset (&dst, 0, sizeof (union sockunion)); + memset (&gateway, 0, sizeof (union sockunion)); /* We fetch each socket variable into sockunion. */ - RTA_ADDR_GET (NULL, RTA_DST, ifm->ifam_addrs, pnt); - RTA_ADDR_GET (NULL, RTA_GATEWAY, ifm->ifam_addrs, pnt); + RTA_ADDR_GET (&dst, RTA_DST, ifm->ifam_addrs, pnt); + RTA_ADDR_GET (&gateway, RTA_GATEWAY, ifm->ifam_addrs, pnt); RTA_ATTR_GET (mask, RTA_NETMASK, ifm->ifam_addrs, pnt); RTA_ADDR_GET (NULL, RTA_GENMASK, ifm->ifam_addrs, pnt); RTA_NAME_GET (ifname, RTA_IFP, ifm->ifam_addrs, pnt, *ifnlen); @@ -519,31 +523,43 @@ ifam_read_mesg (struct ifa_msghdr *ifm, { case AF_INET: { - char buf[2][INET_ADDRSTRLEN]; + char buf[4][INET_ADDRSTRLEN]; zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, " - "addr %s/%d broad %s", - __func__, ifm->ifam_index, + "ifam_flags 0x%x, addr %s/%d broad %s dst %s " + "gateway %s", + __func__, ifm->ifam_index, (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs, + ifm->ifam_flags, inet_ntop(AF_INET,&addr->sin.sin_addr, buf[0],sizeof(buf[0])), ip_masklen(mask->sin.sin_addr), inet_ntop(AF_INET,&brd->sin.sin_addr, - buf[1],sizeof(buf[1]))); + buf[1],sizeof(buf[1])), + inet_ntop(AF_INET,&dst.sin.sin_addr, + buf[2],sizeof(buf[2])), + inet_ntop(AF_INET,&gateway.sin.sin_addr, + buf[3],sizeof(buf[3]))); } break; #ifdef HAVE_IPV6 case AF_INET6: { - char buf[2][INET6_ADDRSTRLEN]; + char buf[4][INET6_ADDRSTRLEN]; zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, " - "addr %s/%d broad %s", + "ifam_flags 0x%x, addr %s/%d broad %s dst %s " + "gateway %s", __func__, ifm->ifam_index, (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs, + ifm->ifam_flags, inet_ntop(AF_INET6,&addr->sin6.sin6_addr, buf[0],sizeof(buf[0])), ip6_masklen(mask->sin6.sin6_addr), inet_ntop(AF_INET6,&brd->sin6.sin6_addr, - buf[1],sizeof(buf[1]))); + buf[1],sizeof(buf[1])), + inet_ntop(AF_INET6,&dst.sin6.sin6_addr, + buf[2],sizeof(buf[2])), + inet_ntop(AF_INET6,&gateway.sin6.sin6_addr, + buf[3],sizeof(buf[3]))); } break; #endif /* HAVE_IPV6 */ @@ -554,7 +570,7 @@ ifam_read_mesg (struct ifa_msghdr *ifm, break; } } - + /* Assert read up end point matches to end point */ if (pnt != end) zlog_warn ("ifam_read() does't read all socket data"); @@ -569,6 +585,7 @@ ifam_read (struct ifa_msghdr *ifam) char ifname[INTERFACE_NAMSIZ]; short ifnlen = 0; char isalias = 0; + int flags = 0; ifname[0] = ifname[INTERFACE_NAMSIZ - 1] = '\0'; @@ -585,6 +602,12 @@ ifam_read (struct ifa_msghdr *ifam) if (ifnlen && strncmp (ifp->name, ifname, INTERFACE_NAMSIZ)) isalias = 1; + /* N.B. The info in ifa_msghdr does not tell us whether the RTA_BRD + field contains a broadcast address or a peer address, so we are forced to + rely upon the interface type. */ + if (if_is_pointopoint(ifp)) + SET_FLAG(flags, ZEBRA_IFA_PEER); + #if 0 /* it might seem cute to grab the interface metric here, however * we're processing an address update message, and so some systems @@ -599,12 +622,12 @@ ifam_read (struct ifa_msghdr *ifam) { case AF_INET: if (ifam->ifam_type == RTM_NEWADDR) - connected_add_ipv4 (ifp, 0, &addr.sin.sin_addr, + connected_add_ipv4 (ifp, flags, &addr.sin.sin_addr, ip_masklen (mask.sin.sin_addr), &brd.sin.sin_addr, (isalias ? ifname : NULL)); else - connected_delete_ipv4 (ifp, 0, &addr.sin.sin_addr, + connected_delete_ipv4 (ifp, flags, &addr.sin.sin_addr, ip_masklen (mask.sin.sin_addr), &brd.sin.sin_addr); break; @@ -616,8 +639,7 @@ ifam_read (struct ifa_msghdr *ifam) SET_IN6_LINKLOCAL_IFINDEX (addr.sin6.sin6_addr, 0); if (ifam->ifam_type == RTM_NEWADDR) - connected_add_ipv6 (ifp, 0, - &addr.sin6.sin6_addr, + connected_add_ipv6 (ifp, flags, &addr.sin6.sin6_addr, ip6_masklen (mask.sin6.sin6_addr), &brd.sin6.sin6_addr, (isalias ? ifname : NULL)); -- cgit v1.2.3 From dc95824ae13d65156dd873a6e784d9a0eed2f39f Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Mon, 13 Aug 2007 16:03:06 +0000 Subject: Merged own patch for the bug #391 (debugging and comments mostly). --- zebra/kernel_socket.c | 110 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 20 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 7bc1b0f9..9d33dd44 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -160,6 +160,7 @@ struct message rtm_type_str[] = #endif /* RTM_IFANNOUNCE */ {0, NULL} }; +int rtm_type_str_max = sizeof (rtm_type_str) / sizeof (struct message) - 1; struct message rtm_flag_str[] = { @@ -737,14 +738,12 @@ rtm_read (struct rt_msghdr *rtm) zebra_flags = 0; - /* Discard self send message. */ - if (rtm->rtm_type != RTM_GET - && (rtm->rtm_pid == pid || rtm->rtm_pid == old_pid)) - return; - /* Read destination and netmask and gateway from rtm message structure. */ flags = rtm_read_mesg (rtm, &dest, &mask, &gate, ifname, &ifnlen); + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type, + LOOKUP (rtm_type_str, rtm->rtm_type)); #ifdef RTF_CLONED /*bsdi, netbsd 1.6*/ if (flags & RTF_CLONED) @@ -786,6 +785,79 @@ rtm_read (struct rt_msghdr *rtm) else p.prefixlen = ip_masklen (mask.sin.sin_addr); + /* Catch self originated messages and match them against our current RIB. + * At the same time, ignore unconfirmed messages, they should be tracked + * by rtm_write() and kernel_rtm_ipv4(). + */ + if (rtm->rtm_type != RTM_GET + && (rtm->rtm_pid == pid || rtm->rtm_pid == old_pid)) + { + char buf[INET_ADDRSTRLEN], gate_buf[INET_ADDRSTRLEN]; + int ret; + if (!(flags & RTF_DONE)) + return; + if (! IS_ZEBRA_DEBUG_RIB) + return; + ret = rib_lookup_ipv4_route (&p, &gate); + inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN); + switch (rtm->rtm_type) + { + case RTM_ADD: + case RTM_GET: + case RTM_CHANGE: + /* The kernel notifies us about a new route in FIB created by us. + Do we have a correspondent entry in our RIB? */ + switch (ret) + { + case ZEBRA_RIB_NOTFOUND: + zlog_debug ("%s: %s %s/%d: desync: RR isn't yet in RIB, while already in FIB", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + break; + case ZEBRA_RIB_FOUND_CONNECTED: + case ZEBRA_RIB_FOUND_NOGATE: + inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN); + zlog_debug ("%s: %s %s/%d: desync: RR is in RIB, but gate differs (ours is %s)", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen, gate_buf); + break; + case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */ + zlog_debug ("%s: %s %s/%d: done Ok", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + rib_lookup_and_dump (&p); + return; + break; + } + break; + case RTM_DELETE: + /* The kernel notifies us about a route deleted by us. Do we still + have it in the RIB? Do we have anything instead? */ + switch (ret) + { + case ZEBRA_RIB_FOUND_EXACT: + zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, while already not in FIB", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + rib_lookup_and_dump (&p); + break; + case ZEBRA_RIB_FOUND_CONNECTED: + case ZEBRA_RIB_FOUND_NOGATE: + zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, plus gate differs", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + rib_lookup_and_dump (&p); + break; + case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */ + zlog_debug ("%s: %s %s/%d: done Ok", + __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + rib_lookup_and_dump (&p); + return; + break; + } + break; + default: + zlog_debug ("%s: %s/%d: warning: loopback RTM of type %s received", + __func__, buf, p.prefixlen, LOOKUP (rtm_type_str, rtm->rtm_type)); + } + return; + } + /* Change, delete the old prefix, we have no further information * to specify the route really */ @@ -903,7 +975,13 @@ rtm_write (int message, { if (!ifp) { - zlog_warn ("no gateway found for interface index %d", index); + char dest_buf[INET_ADDRSTRLEN] = "NULL", mask_buf[INET_ADDRSTRLEN] = "255.255.255.255"; + if (dest) + inet_ntop (AF_INET, &dest->sin.sin_addr, dest_buf, INET_ADDRSTRLEN); + if (mask) + inet_ntop (AF_INET, &mask->sin.sin_addr, mask_buf, INET_ADDRSTRLEN); + zlog_warn ("%s: %s/%s: gate == NULL and no gateway found for ifindex %d", + __func__, dest_buf, mask_buf, index); return -1; } gate = (union sockunion *) & ifp->sdl; @@ -959,11 +1037,13 @@ rtm_write (int message, return ZEBRA_ERR_RTEXIST; if (errno == ENETUNREACH) return ZEBRA_ERR_RTUNREACH; + if (errno == ESRCH) + return ZEBRA_ERR_RTNOEXIST; - zlog_warn ("write : %s (%d)", safe_strerror (errno), errno); - return -1; + zlog_warn ("%s: write : %s (%d)", __func__, safe_strerror (errno), errno); + return ZEBRA_ERR_KERNEL; } - return 0; + return ZEBRA_ERR_NOERROR; } @@ -974,17 +1054,7 @@ rtm_write (int message, static void rtmsg_debug (struct rt_msghdr *rtm) { - const char *type = "Unknown"; - struct message *mes; - - for (mes = rtm_type_str; mes->str; mes++) - if (mes->key == rtm->rtm_type) - { - type = mes->str; - break; - } - - zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, type); + zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, LOOKUP (rtm_type_str, rtm->rtm_type)); rtm_flag_dump (rtm->rtm_flags); zlog_debug ("Kernel: message seq %d", rtm->rtm_seq); zlog_debug ("Kernel: pid %d, rtm_addrs 0x%x", rtm->rtm_pid, rtm->rtm_addrs); -- cgit v1.2.3 From 6da598018c6f866694ecb80a391815a40daaa951 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 17 Aug 2007 14:16:30 +0000 Subject: Fixed bug #394 "RTF_DONE is ignored in rtm_read()" --- zebra/kernel_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 9d33dd44..9d2310b9 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -741,6 +741,8 @@ rtm_read (struct rt_msghdr *rtm) /* Read destination and netmask and gateway from rtm message structure. */ flags = rtm_read_mesg (rtm, &dest, &mask, &gate, ifname, &ifnlen); + if (!(flags & RTF_DONE)) + return; if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type, LOOKUP (rtm_type_str, rtm->rtm_type)); @@ -794,8 +796,6 @@ rtm_read (struct rt_msghdr *rtm) { char buf[INET_ADDRSTRLEN], gate_buf[INET_ADDRSTRLEN]; int ret; - if (!(flags & RTF_DONE)) - return; if (! IS_ZEBRA_DEBUG_RIB) return; ret = rib_lookup_ipv4_route (&p, &gate); -- cgit v1.2.3 From 1ba27564f3852083839bfa1f91889cb46c780f2f Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Tue, 21 Aug 2007 16:15:39 +0000 Subject: Looks like bug #320 is finally fixed now. --- zebra/kernel_socket.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 9d2310b9..ff858bd3 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -472,6 +472,15 @@ ifm_read (struct if_msghdr *ifm) if_delete_update (ifp); } #endif /* RTM_IFANNOUNCE */ + if (if_is_up (ifp)) + { +#if defined(__bsdi__) + if_kvm_get_mtu (ifp); +#else + if_get_mtu (ifp); +#endif /* __bsdi__ */ + if_get_metric (ifp); + } } #ifdef HAVE_NET_RT_IFLIST -- cgit v1.2.3 From 2d844524ad9431ea1e53336dfcfebd3ee6520cb7 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 14 Sep 2007 11:31:55 +0000 Subject: Switch from LOOKUP() to lookup() for rtm_type (see bug #401 for details). --- zebra/kernel_socket.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index ff858bd3..df2b5d80 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -160,7 +160,6 @@ struct message rtm_type_str[] = #endif /* RTM_IFANNOUNCE */ {0, NULL} }; -int rtm_type_str_max = sizeof (rtm_type_str) / sizeof (struct message) - 1; struct message rtm_flag_str[] = { @@ -754,7 +753,7 @@ rtm_read (struct rt_msghdr *rtm) return; if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type, - LOOKUP (rtm_type_str, rtm->rtm_type)); + lookup (rtm_type_str, rtm->rtm_type)); #ifdef RTF_CLONED /*bsdi, netbsd 1.6*/ if (flags & RTF_CLONED) @@ -820,17 +819,17 @@ rtm_read (struct rt_msghdr *rtm) { case ZEBRA_RIB_NOTFOUND: zlog_debug ("%s: %s %s/%d: desync: RR isn't yet in RIB, while already in FIB", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); break; case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_NOGATE: inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN); zlog_debug ("%s: %s %s/%d: desync: RR is in RIB, but gate differs (ours is %s)", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen, gate_buf); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen, gate_buf); break; case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */ zlog_debug ("%s: %s %s/%d: done Ok", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); rib_lookup_and_dump (&p); return; break; @@ -843,18 +842,18 @@ rtm_read (struct rt_msghdr *rtm) { case ZEBRA_RIB_FOUND_EXACT: zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, while already not in FIB", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); rib_lookup_and_dump (&p); break; case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_NOGATE: zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, plus gate differs", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); rib_lookup_and_dump (&p); break; case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */ zlog_debug ("%s: %s %s/%d: done Ok", - __func__, LOOKUP (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); + __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen); rib_lookup_and_dump (&p); return; break; @@ -862,7 +861,7 @@ rtm_read (struct rt_msghdr *rtm) break; default: zlog_debug ("%s: %s/%d: warning: loopback RTM of type %s received", - __func__, buf, p.prefixlen, LOOKUP (rtm_type_str, rtm->rtm_type)); + __func__, buf, p.prefixlen, lookup (rtm_type_str, rtm->rtm_type)); } return; } @@ -1063,7 +1062,7 @@ rtm_write (int message, static void rtmsg_debug (struct rt_msghdr *rtm) { - zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, LOOKUP (rtm_type_str, rtm->rtm_type)); + zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, lookup (rtm_type_str, rtm->rtm_type)); rtm_flag_dump (rtm->rtm_flags); zlog_debug ("Kernel: message seq %d", rtm->rtm_seq); zlog_debug ("Kernel: pid %d, rtm_addrs 0x%x", rtm->rtm_pid, rtm->rtm_addrs); -- cgit v1.2.3 From 96934e6ac6ec9ff6e67131cc8324741b771d5e0d Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 14 Sep 2007 14:56:28 +0000 Subject: + sayonara old_pid! --- zebra/kernel_socket.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index df2b5d80..cb23bf9f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -799,8 +799,7 @@ rtm_read (struct rt_msghdr *rtm) * At the same time, ignore unconfirmed messages, they should be tracked * by rtm_write() and kernel_rtm_ipv4(). */ - if (rtm->rtm_type != RTM_GET - && (rtm->rtm_pid == pid || rtm->rtm_pid == old_pid)) + if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid) { char buf[INET_ADDRSTRLEN], gate_buf[INET_ADDRSTRLEN]; int ret; -- cgit v1.2.3 From 5619f56ba38b255f699f76b327cf82388c4a90cf Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Wed, 24 Oct 2007 13:13:21 +0000 Subject: + fix the bug reported by Milan Kocian (IPv6 route handling was broken by the RIB debug changeset). after --- zebra/kernel_socket.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index cb23bf9f..a91d76f5 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -884,6 +884,11 @@ rtm_read (struct rt_msghdr *rtm) #ifdef HAVE_IPV6 if (dest.sa.sa_family == AF_INET6) { + /* One day we might have a debug section here like one in the + * IPv4 case above. Just ignore own messages at the moment. + */ + if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid) + return; struct prefix_ipv6 p; unsigned int ifindex = 0; -- cgit v1.2.3 From c543a1737173fb438f1d8c06f650b2d0d479f45c Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 10 Jan 2008 15:24:32 +0000 Subject: [link-detect] Try to get BSD link-detect to work properly. 2008-01-10 Ingo Flaschberger * configure.ac: Define HAVE_BSD_LINK_DETECT if is present. * lib/zebra.h: If HAVE_BSD_LINK_DETECT is defined, include . * zebra/ioctl.c: (if_get_flags) If HAVE_BSD_LINK_DETECT, use the SIOCGIFMEDIA ioctl to ascertain link state. * zebra/kernel_socket.c: (bsd_linkdetect_translate) New function to map the ifm_data.ifi_link_state value into the IFF_RUNNING flag. (ifm_read) Call bsd_linkdetect_translate to fix the IFF_RUNNING flag before calling if_flags_update. --- zebra/kernel_socket.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index a91d76f5..cd30631b 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -295,6 +295,18 @@ ifan_read (struct if_announcemsghdr *ifan) } #endif /* RTM_IFANNOUNCE */ +#ifdef HAVE_BSD_LINK_DETECT +/* BSD link detect translation */ +static void +bsd_linkdetect_translate (struct if_msghdr *ifm) +{ + if (ifm->ifm_data.ifi_link_state >= LINK_STATE_UP) + SET_FLAG(ifm->ifm_flags, IFF_RUNNING); + else + UNSET_FLAG(ifm->ifm_flags, IFF_RUNNING); +} +#endif /* HAVE_BSD_LINK_DETECT */ + /* * Handle struct if_msghdr obtained from reading routing socket or * sysctl (from interface_list). There may or may not be sockaddrs @@ -426,6 +438,11 @@ ifm_read (struct if_msghdr *ifm) * structure with ifindex IFINDEX_INTERNAL. */ ifp->ifindex = ifm->ifm_index; + +#ifdef HAVE_BSD_LINK_DETECT /* translate BSD kernel msg for link-state */ + bsd_linkdetect_translate(ifm); +#endif /* HAVE_BSD_LINK_DETECT */ + if_flags_update (ifp, ifm->ifm_flags); #if defined(__bsdi__) if_kvm_get_mtu (ifp); @@ -453,6 +470,10 @@ ifm_read (struct if_msghdr *ifm) return -1; } +#ifdef HAVE_BSD_LINK_DETECT /* translate BSD kernel msg for link-state */ + bsd_linkdetect_translate(ifm); +#endif /* HAVE_BSD_LINK_DETECT */ + /* update flags and handle operative->inoperative transition, if any */ if_flags_update (ifp, ifm->ifm_flags); -- cgit v1.2.3 From 55edb0d446a272907715b0825ff008557174d34a Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Fri, 11 Jan 2008 15:57:13 +0000 Subject: [link-detect] Improve BSD support. 2008-01-11 Andrew J. Schorr * lib/zebra.h: Revert previous change, no need to include here. * zebra/ioctl.c: If HAVE_BSD_LINK_DETECT is defined, include (if_get_flags) Remove debug messages about BSD link state. * zebra/kernel_socket.c: (bsd_linkdetect_translate) If link state is unknown, we should set the IFF_RUNNING flag. --- zebra/kernel_socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index cd30631b..2e04b031 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -300,7 +300,8 @@ ifan_read (struct if_announcemsghdr *ifan) static void bsd_linkdetect_translate (struct if_msghdr *ifm) { - if (ifm->ifm_data.ifi_link_state >= LINK_STATE_UP) + if ((ifm->ifm_data.ifi_link_state >= LINK_STATE_UP) || + (ifm->ifm_data.ifi_link_state == LINK_STATE_UNKNOWN)) SET_FLAG(ifm->ifm_flags, IFF_RUNNING); else UNSET_FLAG(ifm->ifm_flags, IFF_RUNNING); -- cgit v1.2.3 From 1423c809cc4ddc2e013ba6264c49a11e5719c6f2 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 14 Aug 2008 17:59:25 +0100 Subject: [lib] mes_lookup string lookup table argument should be marked const 2008-08-14 Stephen Hemminger * lib/log.{c,h}: struct message argument should point to const * */*.c: adjust to suit, Signed-off-by: Paul Jakma --- zebra/kernel_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 2e04b031..e77b9b78 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -126,7 +126,7 @@ extern struct zebra_t zebrad; (LEN) = 0; \ } /* Routing socket message types. */ -struct message rtm_type_str[] = +const struct message rtm_type_str[] = { {RTM_ADD, "RTM_ADD"}, {RTM_DELETE, "RTM_DELETE"}, -- cgit v1.2.3