diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ChangeLog | 23 | ||||
-rw-r--r-- | lib/if.c | 47 | ||||
-rw-r--r-- | lib/if.h | 34 | ||||
-rw-r--r-- | lib/prefix.h | 6 | ||||
-rw-r--r-- | lib/zclient.c | 6 |
5 files changed, 66 insertions, 50 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index f076e2f0..914cc5e8 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,26 @@ +2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu> + + * 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. + 2006-10-14 Paul Jakma <paul.jakma@sun.com> * if.c: (general) Handle upgrades from SUNWzebra, which tried @@ -275,7 +275,6 @@ if_lookup_address (struct in_addr src) int bestlen = 0; struct listnode *cnode; struct interface *ifp; - struct prefix *p; struct connected *c; struct interface *match; @@ -289,25 +288,12 @@ if_lookup_address (struct in_addr src) { for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { - if (c->address && (c->address->family == AF_INET)) + if (c->address && (c->address->family == AF_INET) && + prefix_match(CONNECTED_PREFIX(c), &addr) && + (c->address->prefixlen > bestlen)) { - if (CONNECTED_POINTOPOINT_HOST(c)) - { - /* PTP links are conventionally identified - by the address of the far end - MAG */ - if (IPV4_ADDR_SAME (&c->destination->u.prefix4, &src)) - return ifp; - } - else - { - p = c->address; - - if (prefix_match (p, &addr) && p->prefixlen > bestlen) - { - bestlen = p->prefixlen; - match = ifp; - } - } + bestlen = c->address->prefixlen; + match = ifp; } } } @@ -728,7 +714,6 @@ connected_lookup_address (struct interface *ifp, struct in_addr dst) { struct prefix addr; struct listnode *cnode; - struct prefix *p; struct connected *c; struct connected *match; @@ -740,24 +725,10 @@ connected_lookup_address (struct interface *ifp, struct in_addr dst) for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { - if (c->address && (c->address->family == AF_INET)) - { - if (CONNECTED_POINTOPOINT_HOST(c)) - { - /* PTP links are conventionally identified - by the address of the far end - MAG */ - if (IPV4_ADDR_SAME (&c->destination->u.prefix4, &dst)) - return c; - } - else - { - p = c->address; - - if (prefix_match (p, &addr) && - (!match || (p->prefixlen > match->address->prefixlen))) - match = c; - } - } + if (c->address && (c->address->family == AF_INET) && + prefix_match(CONNECTED_PREFIX(c), &addr) && + (!match || (c->address->prefixlen > match->address->prefixlen))) + match = c; } return match; } @@ -154,26 +154,38 @@ struct connected /* Flags for connected address. */ u_char flags; -#define ZEBRA_IFA_SECONDARY (1 << 0) +#define ZEBRA_IFA_SECONDARY (1 << 0) +#define ZEBRA_IFA_PEER (1 << 1) + /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if + a peer address has been configured. If this flag is set, + the destination field must contain the peer address. + Otherwise, if this flag is not set, the destination address + will either contain a broadcast address or be NULL. + */ /* Address of connected network. */ struct prefix *address; - struct prefix *destination; /* broadcast or peer address; may be NULL */ + + /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set. + Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */ + struct prefix *destination; /* Label for Linux 2.2.X and upper. */ char *label; }; -/* Given an IPV4 struct connected, this macro determines whether a /32 - peer address has been supplied (i.e. there is no subnet assigned) */ -#define CONNECTED_DEST_HOST(C) \ - ((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN)) +/* Does the destination field contain a peer address? */ +#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER) + +/* Prefix to insert into the RIB */ +#define CONNECTED_PREFIX(C) \ + (CONNECTED_PEER(C) ? (C)->destination : (C)->address) -/* Given an IPV4 struct connected, this macro determins whether it is - a point-to-point link with a /32 peer address (i.e. there - is no dedicated subnet for the PtP link) */ -#define CONNECTED_POINTOPOINT_HOST(C) \ - (((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C)) +/* Identifying address. We guess that if there's a peer address, but the + local address is in the same prefix, then the local address may be unique. */ +#define CONNECTED_ID(C) \ + ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\ + (C)->destination : (C)->address) /* Interface hook sort. */ #define IF_NEW_HOOK 0 diff --git a/lib/prefix.h b/lib/prefix.h index 7afe7a1e..f2a2adfa 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -151,6 +151,9 @@ extern void prefix_ipv4_free (struct prefix_ipv4 *); extern int str2prefix_ipv4 (const char *, struct prefix_ipv4 *); extern void apply_mask_ipv4 (struct prefix_ipv4 *); +#define PREFIX_COPY_IPV4(DST, SRC) \ + *((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC)); + extern int prefix_ipv4_any (const struct prefix_ipv4 *); extern void apply_classful_mask_ipv4 (struct prefix_ipv4 *); @@ -172,6 +175,9 @@ extern void prefix_ipv6_free (struct prefix_ipv6 *); extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *); extern void apply_mask_ipv6 (struct prefix_ipv6 *); +#define PREFIX_COPY_IPV6(DST, SRC) \ + *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC)); + extern int ip6_masklen (struct in6_addr); extern void masklen2ip6 (int, struct in6_addr *); diff --git a/lib/zclient.c b/lib/zclient.c index a253af61..09a7d25e 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -780,7 +780,11 @@ zebra_interface_address_read (int type, struct stream *s) ifc = connected_add_by_prefix(ifp, &p,(memconstant(&d.u.prefix,0,plen) ? NULL : &d)); if (ifc != NULL) - ifc->flags = ifc_flags; + { + ifc->flags = ifc_flags; + if (ifc->destination) + ifc->destination->prefixlen = ifc->address->prefixlen; + } } else { |