diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-11-12 02:03:59 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-11-12 02:03:59 +0100 |
commit | d44e686e9bcae5850115c0e1adfe24523dce61ee (patch) | |
tree | 88feb4c9e43fe547db954496ec5d9eb66b307f52 | |
parent | fe9f1a6dedda6bab23cbb605d1cd5db6cd3e2468 (diff) |
Follow-up commit on integrated BIRD
Use net_addr for interface address prefixes, support net_addr in
configuration parser.
-rw-r--r-- | conf/confbase.Y | 40 | ||||
-rw-r--r-- | lib/net.h | 5 | ||||
-rw-r--r-- | nest/config.Y | 13 | ||||
-rw-r--r-- | nest/iface.c | 31 | ||||
-rw-r--r-- | nest/iface.h | 6 | ||||
-rw-r--r-- | nest/neighbor.c | 2 | ||||
-rw-r--r-- | nest/rt-dev.c | 4 | ||||
-rw-r--r-- | proto/ospf/config.Y | 9 | ||||
-rw-r--r-- | proto/ospf/hello.c | 6 | ||||
-rw-r--r-- | proto/ospf/iface.c | 32 | ||||
-rw-r--r-- | proto/ospf/ospf.c | 9 | ||||
-rw-r--r-- | proto/ospf/ospf.h | 4 | ||||
-rw-r--r-- | proto/ospf/packet.c | 2 | ||||
-rw-r--r-- | proto/ospf/topology.c | 54 | ||||
-rw-r--r-- | proto/radv/config.Y | 10 | ||||
-rw-r--r-- | proto/radv/packets.c | 25 | ||||
-rw-r--r-- | proto/radv/radv.c | 2 | ||||
-rw-r--r-- | proto/radv/radv.h | 5 | ||||
-rw-r--r-- | proto/static/config.Y | 7 | ||||
-rw-r--r-- | proto/static/static.c | 35 | ||||
-rw-r--r-- | proto/static/static.h | 4 | ||||
-rw-r--r-- | sysdep/unix/krt.Y | 7 |
22 files changed, 163 insertions, 149 deletions
diff --git a/conf/confbase.Y b/conf/confbase.Y index 64a636cf..3ad0c5f0 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -41,6 +41,8 @@ CF_DECLS ip_addr a; ip4_addr ip4; ip6_addr ip6; + net_addr_union net; + net_addr *net_ptr; struct symbol *s; char *t; struct rtable_config *r; @@ -78,10 +80,11 @@ CF_DECLS %type <i32> expr_us %type <time> datetime %type <a> ipa ipa_raw -%type <px> prefix prefix_or_ipa -%type <t> text -%type <t> text_or_none -%type <t> opttext +%type <px> prefix +%type <net> net_ip4 net_ip6 net_ip net_or_ipa +%type <net_ptr> net_any + +%type <t> text opttext %nonassoc PREFIX_DUMMY %left AND OR @@ -169,6 +172,25 @@ ipa_scope: | '%' SYM { $$ = if_get_by_name($2->name); } ; + +/* XXXX - symbols and tests */ + +net_ip4: IP4 pxlen { $$.ip4 = NET_ADDR_IP4($1, $2); } + +net_ip6: IP6 pxlen { $$.ip6 = NET_ADDR_IP6($1, $2); } + +net_ip: net_ip4 | net_ip6 ; + +net_any: net_ip { $$ = cfg_alloc($1.n.length); net_copy($$, &($1.n)); } + +net_or_ipa: + net_ip4 + | net_ip6 + | IP4 { $$.ip4 = NET_ADDR_IP4($1, IP4_MAX_PREFIX_LENGTH); } + | IP6 { $$.ip6 = NET_ADDR_IP6($1, IP6_MAX_PREFIX_LENGTH); } + ; + + prefix: ipa pxlen { if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix"); @@ -176,11 +198,6 @@ prefix: } ; -prefix_or_ipa: - prefix - | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; } - ; - pxlen: '/' expr { if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2); @@ -208,11 +225,6 @@ text: } ; -text_or_none: - TEXT { $$ = $1; } - | { $$ = NULL; } - ; - opttext: TEXT | /* empty */ { $$ = NULL; } @@ -24,8 +24,8 @@ typedef struct net_addr { u8 type; u8 pxlen; u16 length; + u8 data[16]; u64 align[0]; - u32 space[4]; } net_addr; typedef struct net_addr_ip4 { @@ -207,6 +207,9 @@ int net_classify(const net_addr *N); char * net_format(const net_addr *N, char *buf, int buflen); +int ipa_in_netX(const ip_addr A, const net_addr *N); +int net_in_netX(const net_addr *A, const net_addr *N); + #endif diff --git a/nest/config.Y b/nest/config.Y index 4353db79..537a363c 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -30,7 +30,7 @@ iface_patt_check(void) struct iface_patt_node *pn; WALK_LIST(pn, this_ipatt->ipn_list) - if (!pn->pattern || pn->pxlen) + if (!pn->pattern || pn->prefix.pxlen) /* XXXX */ cf_error("Interface name/mask expected, not IP prefix"); } @@ -284,9 +284,8 @@ iface_patt_node_init: ; iface_patt_node_body: - TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; } - | prefix_or_ipa { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; } - | TEXT prefix_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; } + TEXT { this_ipn->pattern = $1; net_fill_ip6(&this_ipn->prefix, IP6_NONE, 0); /* XXXX */ } + | opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.n; } ; iface_negate: @@ -479,11 +478,11 @@ r_args: $$->prefix = $2.addr; $$->pxlen = $2.len; } - | r_args FOR prefix_or_ipa { + | r_args FOR net_or_ipa { $$ = $1; if ($$->pxlen != 256) cf_error("Only one prefix expected"); - $$->prefix = $3.addr; - $$->pxlen = $3.len; + $$->prefix = IPA_NONE; /* XXXX */ + $$->pxlen = 0; /* XXXX */ $$->show_for = 1; } | r_args TABLE SYM { diff --git a/nest/iface.c b/nest/iface.c index 4d73c2a4..5d3c0e60 100644 --- a/nest/iface.c +++ b/nest/iface.c @@ -46,7 +46,7 @@ list iface_list; void ifa_dump(struct ifa *a) { - debug("\t%I, net %I/%-2d bc %I -> %I%s%s%s\n", a->ip, a->prefix, a->pxlen, a->brd, a->opposite, + debug("\t%I, net %N bc %I -> %I%s%s%s\n", a->ip, &a->prefix, a->brd, a->opposite, (a->flags & IF_UP) ? "" : " DOWN", (a->flags & IA_PRIMARY) ? "" : " SEC", (a->flags & IA_PEER) ? "PEER" : ""); @@ -141,10 +141,9 @@ ifa_send_notify(struct proto *p, unsigned c, struct ifa *a) if (p->ifa_notify) { if (p->debug & D_IFACES) - log(L_TRACE "%s < %s address %I/%d on interface %s %s", + log(L_TRACE "%s < %s address %N on interface %s %s", p->name, (a->flags & IA_PRIMARY) ? "primary" : "secondary", - a->prefix, a->pxlen, a->iface->name, - (c & IF_CHANGE_UP) ? "added" : "removed"); + &a->prefix, a->iface->name, (c & IF_CHANGE_UP) ? "added" : "removed"); p->ifa_notify(p, c, a); } } @@ -500,8 +499,7 @@ ifa_recalc_all_primary_addresses(void) static inline int ifa_same(struct ifa *a, struct ifa *b) { - return ipa_equal(a->ip, b->ip) && ipa_equal(a->prefix, b->prefix) && - a->pxlen == b->pxlen; + return ipa_equal(a->ip, b->ip) && net_equal(&a->prefix, &b->prefix); } @@ -586,7 +584,6 @@ ifa_delete(struct ifa *a) u32 if_choose_router_id(struct iface_patt *mask, u32 old_id) { -#ifndef IPV6 struct iface *i; struct ifa *a, *b; @@ -599,6 +596,9 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id) WALK_LIST(a, i->addrs) { + if (a->prefix.type != NET_IP4) + continue; + if (a->flags & IA_SECONDARY) continue; @@ -623,10 +623,6 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id) log(L_INFO "Chosen router ID %R according to interface %s", id, b->iface->name); return id; - -#else - return 0; -#endif } /** @@ -669,17 +665,17 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a) continue; } - if (p->pxlen == 0) + if (p->prefix.pxlen == 0) return pos; if (!a) continue; - if (ipa_in_net(a->ip, p->prefix, p->pxlen)) + if (ipa_in_netX(a->ip, &p->prefix)) return pos; if ((a->flags & IA_PEER) && - ipa_in_net(a->opposite, p->prefix, p->pxlen)) + ipa_in_netX(a->opposite, &p->prefix)) return pos; continue; @@ -713,8 +709,7 @@ iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb) (!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */ (!y->pattern && x->pattern) || ((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) || - !ipa_equal(x->prefix, y->prefix) || - (x->pxlen != y->pxlen)) + !net_equal(&x->prefix, &y->prefix)) return 0; x = (void *) x->n.next; y = (void *) y->n.next; @@ -754,7 +749,7 @@ if_show_addr(struct ifa *a) else opp[0] = 0; cli_msg(-1003, "\t%I/%d (%s%s, scope %s)", - a->ip, a->pxlen, + a->ip, a->prefix.pxlen, (a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "Unselected", opp, ip_scope_text(a->scope)); } @@ -804,7 +799,7 @@ if_show_summary(void) WALK_LIST(i, iface_list) { if (i->addr) - bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen); + bsprintf(addr, "%I/%d", i->addr->ip, i->addr->prefix.pxlen); else addr[0] = 0; cli_msg(-1005, "%-9s %-5s %s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr); diff --git a/nest/iface.h b/nest/iface.h index 56710e4a..c4f414ec 100644 --- a/nest/iface.h +++ b/nest/iface.h @@ -19,9 +19,8 @@ struct pool; struct ifa { /* Interface address */ node n; struct iface *iface; /* Interface this address belongs to */ + net_addr prefix; /* Network prefix */ ip_addr ip; /* IP address of this host */ - ip_addr prefix; /* Network prefix */ - unsigned pxlen; /* Prefix length */ ip_addr brd; /* Broadcast address */ ip_addr opposite; /* Opposite end of a point-to-point link */ unsigned scope; /* Interface address scope */ @@ -148,8 +147,7 @@ struct iface_patt_node { node n; int positive; byte *pattern; - ip_addr prefix; - int pxlen; + net_addr prefix; }; struct iface_patt { diff --git a/nest/neighbor.c b/nest/neighbor.c index 1685d67e..b8832f2f 100644 --- a/nest/neighbor.c +++ b/nest/neighbor.c @@ -79,7 +79,7 @@ if_connected(ip_addr *a, struct iface *i, struct ifa **ap) } else { - if (ipa_in_net(*a, b->prefix, b->pxlen)) + if (ipa_in_netX(*a, &b->prefix)) { #ifndef IPV6 if ((b->pxlen < (BITS_PER_IP_ADDRESS - 1)) && diff --git a/nest/rt-dev.c b/nest/rt-dev.c index e8408116..f94933d5 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -45,7 +45,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad) net *n; DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip); - n = net_find_ipa(p->table, ad->prefix, ad->pxlen); + n = net_find(p->table, &ad->prefix); if (!n) { DBG("dev_if_notify: device shutdown: prefix not found\n"); @@ -77,7 +77,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad) }; a = rta_lookup(&a0); - n = net_get_ipa(p->table, ad->prefix, ad->pxlen); + n = net_get(p->table, &ad->prefix); e = rte_get_temp(a); e->net = n; e->pflags = 0; diff --git a/proto/ospf/config.Y b/proto/ospf/config.Y index 706ab7ac..e8fb7f2e 100644 --- a/proto/ospf/config.Y +++ b/proto/ospf/config.Y @@ -211,10 +211,10 @@ ospf_stubnet: ; ospf_stubnet_start: - prefix { + net_ip { this_stubnet = cfg_allocz(sizeof(struct ospf_stubnet_config)); add_tail(&this_area->stubnet_list, NODE this_stubnet); - this_stubnet->px = $1; + this_stubnet->prefix = $1.n; this_stubnet->cost = COST_D; } ; @@ -321,12 +321,11 @@ pref_list: pref_item: pref_base pref_opt ';' ; -pref_base: prefix +pref_base: net_ip { this_pref = cfg_allocz(sizeof(struct area_net_config)); add_tail(this_nets, NODE this_pref); - this_pref->px.addr = $1.addr; - this_pref->px.len = $1.len; + this_pref->prefix = $1.n; } ; diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 8b550e71..3fbb6167 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -74,7 +74,7 @@ ospf_send_hello(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn) ((ifa->type == OSPF_IT_PTP) && !ifa->ptp_netmask)) ps->netmask = 0; else - ps->netmask = htonl(u32_mkmask(ifa->addr->pxlen)); + ps->netmask = htonl(u32_mkmask(ifa->addr->prefix.pxlen)); ps->helloint = ntohs(ifa->helloint); ps->options = ifa->oa->options; @@ -198,7 +198,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa, /* RFC 2328 10.5 */ /* - * We may not yet havethe associate neighbor, so we use Router ID from the + * We may not yet have the associate neighbor, so we use Router ID from the * packet instead of one from the neighbor structure for log messages. */ u32 rcv_rid = ntohl(pkt->routerid); @@ -224,7 +224,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa, int pxlen = u32_masklen(ntohl(ps->netmask)); if ((ifa->type != OSPF_IT_VLINK) && (ifa->type != OSPF_IT_PTP) && - (pxlen != ifa->addr->pxlen)) + (pxlen != ifa->addr->prefix.pxlen)) DROP("prefix length mismatch", pxlen); neighbors = ps->neighbors; diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 3c0cee18..5d37b005 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -237,8 +237,8 @@ ospf_iface_down(struct ospf_iface *ifa) OSPF_TRACE(D_EVENTS, "Removing interface %s (peer %I) from area %R", ifa->ifname, ifa->addr->opposite, ifa->oa->areaid); else - OSPF_TRACE(D_EVENTS, "Removing interface %s (%I/%d) from area %R", - ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen, ifa->oa->areaid); + OSPF_TRACE(D_EVENTS, "Removing interface %s (%N) from area %R", + ifa->ifname, &ifa->addr->prefix, ifa->oa->areaid); /* First of all kill all the related vlinks */ WALK_LIST(iff, p->iface_list) @@ -550,8 +550,8 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i OSPF_TRACE(D_EVENTS, "Adding interface %s (peer %I) to area %R", iface->name, addr->opposite, oa->areaid); else - OSPF_TRACE(D_EVENTS, "Adding interface %s (%I/%d) to area %R", - iface->name, addr->prefix, addr->pxlen, oa->areaid); + OSPF_TRACE(D_EVENTS, "Adding interface %s (%N) to area %R", + iface->name, &addr->prefix, oa->areaid); pool = rp_new(p->p.pool, "OSPF Interface"); ifa = mb_allocz(pool, sizeof(struct ospf_iface)); @@ -627,7 +627,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i should be used). Because OSPFv3 iface is not subnet-specific, there is no need for ipa_in_net() check */ - if (ospf_is_v2(p) && !ipa_in_net(nb->ip, addr->prefix, addr->pxlen)) + if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &addr->prefix)) continue; if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip)) @@ -640,7 +640,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i add_tail(&oa->po->iface_list, NODE ifa); struct object_lock *lock = olock_new(pool); - lock->addr = ospf_is_v2(p) ? ifa->addr->prefix : IPA_NONE; + lock->addr = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE; lock->type = OBJLOCK_IP; lock->port = OSPF_PROTO; lock->inst = ifa->instance_id; @@ -886,7 +886,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) WALK_LIST(nb, new->nbma_list) { /* See related note in ospf_iface_new() */ - if (ospf_is_v2(p) && !ipa_in_net(nb->ip, ifa->addr->prefix, ifa->addr->pxlen)) + if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &ifa->addr->prefix)) continue; if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip)) @@ -1073,6 +1073,9 @@ ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a) { struct ospf_proto *p = (struct ospf_proto *) P; + if (a->prefix.type != NET_IP4) + return; + if (a->flags & IA_SECONDARY) return; @@ -1102,6 +1105,9 @@ ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a) { struct ospf_proto *p = (struct ospf_proto *) P; + if (a->prefix.type != NET_IP6) + return; + if (a->flags & IA_SECONDARY) return; @@ -1154,6 +1160,9 @@ ospf_reconfigure_ifaces2(struct ospf_proto *p) WALK_LIST(a, iface->addrs) { + if (a->prefix.type != NET_IP4) + continue; + if (a->flags & IA_SECONDARY) continue; @@ -1172,8 +1181,8 @@ ospf_reconfigure_ifaces2(struct ospf_proto *p) continue; /* Hard restart */ - log(L_INFO "%s: Restarting interface %s (%I/%d) in area %R", - p->p.name, ifa->ifname, a->prefix, a->pxlen, s.oa->areaid); + log(L_INFO "%s: Restarting interface %s (%N) in area %R", + p->p.name, ifa->ifname, &a->prefix, s.oa->areaid); ospf_iface_shutdown(ifa); ospf_iface_remove(ifa); } @@ -1197,6 +1206,9 @@ ospf_reconfigure_ifaces3(struct ospf_proto *p) WALK_LIST(a, iface->addrs) { + if (a->prefix.type != NET_IP6) + continue; + if (a->flags & IA_SECONDARY) continue; @@ -1328,7 +1340,7 @@ ospf_iface_info(struct ospf_iface *ifa) else if (ifa->addr->flags & IA_PEER) cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite); else - cli_msg(-1015, "Interface %s (%I/%d)", ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen); + cli_msg(-1015, "Interface %s (%N)", ifa->ifname, ifa->addr->prefix); cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more); cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid); diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index bfe51e66..cdc62d0a 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -114,7 +114,6 @@ add_area_nets(struct ospf_area *oa, struct ospf_area_config *ac) struct ospf_proto *p = oa->po; struct area_net_config *anc; struct area_net *an; - net_addr net; fib_init(&oa->net_fib, p->p.pool, ospf_is_v2(p) ? NET_IP4 : NET_IP6, sizeof(struct area_net), OFFSETOF(struct area_net, fn), 0, NULL); @@ -123,17 +122,13 @@ add_area_nets(struct ospf_area *oa, struct ospf_area_config *ac) WALK_LIST(anc, ac->net_list) { - /* XXXX we should dispatch by ospf version, not by px.addr */ - net_fill_ipa(&net, anc->px.addr, anc->px.len); - an = fib_get(&oa->net_fib, &net); + an = fib_get(&oa->net_fib, &anc->prefix); an->hidden = anc->hidden; } WALK_LIST(anc, ac->enet_list) { - /* XXXX ditto */ - net_fill_ipa(&net, anc->px.addr, anc->px.len); - an = fib_get(&oa->enet_fib, &net); + an = fib_get(&oa->enet_fib, &anc->prefix); an->hidden = anc->hidden; an->tag = anc->tag; } diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index df77dda9..6291ae1a 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -125,7 +125,7 @@ struct ospf_area_config struct area_net_config { node n; - struct prefix px; + net_addr prefix; u32 tag; u8 hidden; }; @@ -142,7 +142,7 @@ struct area_net struct ospf_stubnet_config { node n; - struct prefix px; + net_addr prefix; u32 cost; u8 hidden; u8 summary; diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c index 606127f2..0975b251 100644 --- a/proto/ospf/packet.c +++ b/proto/ospf/packet.c @@ -236,7 +236,7 @@ ospf_rx_hook(sock *sk, int len) return 1; int src_local, dst_local, dst_mcast; - src_local = ipa_in_net(sk->faddr, ifa->addr->prefix, ifa->addr->pxlen); + src_local = ipa_in_netX(sk->faddr, &ifa->addr->prefix); dst_local = ipa_equal(sk->laddr, ifa->addr->ip); dst_mcast = ipa_equal(sk->laddr, ifa->all_routers) || ipa_equal(sk->laddr, ifa->des_routers); diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index 47832771..59e76019 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -629,12 +629,12 @@ configured_stubnet(struct ospf_area *oa, struct ifa *a) { if (sn->summary) { - if (ipa_in_net(a->prefix, sn->px.addr, sn->px.len) && (a->pxlen >= sn->px.len)) + if (net_in_netX(&a->prefix, &sn->prefix)) return 1; } else { - if (ipa_equal(a->prefix, sn->px.addr) && (a->pxlen == sn->px.len)) + if (net_equal(&a->prefix, &sn->prefix)) return 1; } } @@ -782,7 +782,8 @@ prepare_rt2_lsa_body(struct ospf_proto *p, struct ospf_area *oa) (ifa->type == OSPF_IT_PTMP)) add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(ifa->addr->ip), 0xffffffff, 0); else - add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(ifa->addr->prefix), u32_mkmask(ifa->addr->pxlen), ifa->cost); + add_rt2_lsa_link(p, LSART_STUB, ip4_to_u32(net4_prefix(&ifa->addr->prefix)), + u32_mkmask(net4_pxlen(&ifa->addr->prefix)), ifa->cost); i++; ifa->rt_pos_end = i; @@ -791,7 +792,8 @@ prepare_rt2_lsa_body(struct ospf_proto *p, struct ospf_area *oa) struct ospf_stubnet_config *sn; WALK_LIST(sn, oa->ac->stubnet_list) if (!sn->hidden) - add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(sn->px.addr), u32_mkmask(sn->px.len), sn->cost), i++; + add_rt2_lsa_link(p, LSART_STUB, ip4_to_u32(net4_prefix(&sn->prefix)), + u32_mkmask(net4_pxlen(&sn->prefix)), sn->cost), i++; struct ospf_lsa_rt *rt = p->lsab; /* Store number of links in lower half of options */ @@ -908,7 +910,7 @@ prepare_net2_lsa_body(struct ospf_proto *p, struct ospf_iface *ifa) ASSERT(p->lsab_used == 0); net = lsab_alloc(p, sizeof(struct ospf_lsa_net) + 4 * nodes); - net->optx = u32_mkmask(ifa->addr->pxlen); + net->optx = u32_mkmask(ifa->addr->prefix.pxlen); net->routers[0] = p->router_id; WALK_LIST(n, ifa->neigh_list) @@ -1179,7 +1181,7 @@ use_gw_for_fwaddr(struct ospf_proto *p, ip_addr gw, struct iface *iface) WALK_LIST(ifa, p->iface_list) if ((ifa->iface == iface) && - (!ospf_is_v2(p) || ipa_in_net(gw, ifa->addr->prefix, ifa->addr->pxlen))) + (!ospf_is_v2(p) || ipa_in_netX(gw, &ifa->addr->prefix))) return 1; return 0; @@ -1217,7 +1219,8 @@ find_surrogate_fwaddr(struct ospf_proto *p, struct ospf_area *oa) { WALK_LIST(a, ifa->iface->addrs) { - if ((a->flags & IA_SECONDARY) || + if ((a->prefix.type != NET_IP6) || + (a->flags & IA_SECONDARY) || (a->flags & IA_PEER) || (a->scope <= SCOPE_LINK)) continue; @@ -1310,12 +1313,11 @@ ospf_rt_notify(struct proto *P, rtable *tbl UNUSED, net *n, rte *new, rte *old U */ static inline void -lsab_put_prefix(struct ospf_proto *p, ip6_addr prefix, u32 pxlen, u32 cost) +lsab_put_prefix(struct ospf_proto *p, net_addr *net, u32 cost) { - net_addr_ip6 net = NET_ADDR_IP6(prefix, pxlen); - void *buf = lsab_alloc(p, IPV6_PREFIX_SPACE(pxlen)); - u8 flags = (pxlen < IP6_MAX_PREFIX_LENGTH) ? 0 : OPT_PX_LA; - ospf_put_ipv6_prefix(buf, (net_addr *) &net, flags, cost); + void *buf = lsab_alloc(p, IPV6_PREFIX_SPACE(net6_pxlen(net))); + u8 flags = (net6_pxlen(net) < IP6_MAX_PREFIX_LENGTH) ? 0 : OPT_PX_LA; + ospf_put_ipv6_prefix(buf, net, flags, cost); } static void @@ -1333,11 +1335,12 @@ prepare_link_lsa_body(struct ospf_proto *p, struct ospf_iface *ifa) struct ifa *a; WALK_LIST(a, ifa->iface->addrs) { - if ((a->flags & IA_SECONDARY) || - (a->scope < SCOPE_SITE)) + if ((a->prefix.type != NET_IP6) || + (a->flags & IA_SECONDARY) || + (a->scope <= SCOPE_LINK)) continue; - lsab_put_prefix(p, a->prefix, a->pxlen, 0); + lsab_put_prefix(p, &a->prefix, 0); i++; } @@ -1404,12 +1407,13 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa) struct ifa *a; WALK_LIST(a, ifa->iface->addrs) { - if ((a->flags & IA_SECONDARY) || + if ((a->prefix.type != NET_IP6) || + (a->flags & IA_SECONDARY) || (a->flags & IA_PEER) || (a->scope <= SCOPE_LINK)) continue; - if (((a->pxlen < IP6_MAX_PREFIX_LENGTH) && net_lsa) || + if (((a->prefix.pxlen < IP6_MAX_PREFIX_LENGTH) && net_lsa) || configured_stubnet(oa, a)) continue; @@ -1417,11 +1421,12 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa) (ifa->state == OSPF_IS_LOOP) || (ifa->type == OSPF_IT_PTMP)) { - lsab_put_prefix(p, a->ip, IP6_MAX_PREFIX_LENGTH, 0); + net_addr_ip6 net = NET_ADDR_IP6(a->ip, IP6_MAX_PREFIX_LENGTH); + lsab_put_prefix(p, (net_addr *) &net, 0); host_addr = 1; } else - lsab_put_prefix(p, a->prefix, a->pxlen, ifa->cost); + lsab_put_prefix(p, &a->prefix, ifa->cost); i++; } @@ -1432,8 +1437,8 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa) WALK_LIST(sn, oa->ac->stubnet_list) if (!sn->hidden) { - lsab_put_prefix(p, sn->px.addr, sn->px.len, sn->cost); - if (sn->px.len == IP6_MAX_PREFIX_LENGTH) + lsab_put_prefix(p, &sn->prefix, sn->cost); + if (sn->prefix.pxlen == IP6_MAX_PREFIX_LENGTH) host_addr = 1; i++; } @@ -1450,11 +1455,14 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa) struct ifa *a; WALK_LIST(a, ifa->iface->addrs) { - if ((a->flags & IA_SECONDARY) || (a->scope <= SCOPE_LINK)) + if ((a->prefix.type != NET_IP6) || + (a->flags & IA_SECONDARY) || + (a->scope <= SCOPE_LINK)) continue; /* Found some IP */ - lsab_put_prefix(p, a->ip, IP6_MAX_PREFIX_LENGTH, 0); + net_addr_ip6 net = NET_ADDR_IP6(a->ip, IP6_MAX_PREFIX_LENGTH); + lsab_put_prefix(p, (net_addr *) &net, 0); i++; goto done; } diff --git a/proto/radv/config.Y b/proto/radv/config.Y index da300667..efb474a6 100644 --- a/proto/radv/config.Y +++ b/proto/radv/config.Y @@ -53,9 +53,8 @@ radv_proto_item: | PREFIX radv_prefix { add_tail(&RADV_CFG->pref_list, NODE this_radv_prefix); } | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_CFG->rdnss_list, &radv_dns_list); } | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_CFG->dnssl_list, &radv_dns_list); } - | TRIGGER prefix { - RADV_CFG->trigger_prefix = $2.addr; - RADV_CFG->trigger_pxlen = $2.len; + | TRIGGER net_any { + RADV_CFG->trigger = $2; RADV_CFG->trigger_valid = 1; } ; @@ -148,11 +147,10 @@ radv_iface: radv_iface_start iface_patt_list_nopx radv_iface_opt_list radv_iface_finish; -radv_prefix_start: prefix +radv_prefix_start: net_ip6 { this_radv_prefix = cfg_allocz(sizeof(struct radv_prefix_config)); - RADV_PREFIX->prefix = $1.addr; - RADV_PREFIX->pxlen = $1.len; + RADV_PREFIX->prefix = $1.ip6; RADV_PREFIX->onlink = 1; RADV_PREFIX->autonomous = 1; diff --git a/proto/radv/packets.c b/proto/radv/packets.c index 3862af8d..a38b58b2 100644 --- a/proto/radv/packets.c +++ b/proto/radv/packets.c @@ -38,7 +38,7 @@ struct radv_opt_prefix u32 valid_lifetime; u32 preferred_lifetime; u32 reserved; - ip_addr prefix; + ip6_addr prefix; }; #define OPT_PX_ONLINK 0x80 @@ -58,7 +58,7 @@ struct radv_opt_rdnss u8 length; u16 reserved; u32 lifetime; - ip_addr servers[]; + ip6_addr servers[]; }; struct radv_opt_dnssl @@ -90,11 +90,11 @@ radv_prefix_match(struct radv_iface *ifa, struct ifa *a) return NULL; WALK_LIST(pc, ifa->cf->pref_list) - if ((a->pxlen >= pc->pxlen) && ipa_in_net(a->prefix, pc->prefix, pc->pxlen)) + if (net_in_netX(&a->prefix, (net_addr *) &pc->prefix)) return pc; WALK_LIST(pc, cf->pref_list) - if ((a->pxlen >= pc->pxlen) && ipa_in_net(a->prefix, pc->prefix, pc->pxlen)) + if (net_in_netX(&a->prefix, (net_addr *) &pc->prefix)) return pc; return &default_prefix; @@ -109,7 +109,7 @@ radv_prepare_rdnss(struct radv_iface *ifa, list *rdnss_list, char **buf, char *b { struct radv_rdnss_config *rcf_base = rcf; struct radv_opt_rdnss *op = (void *) *buf; - int max_i = (bufend - *buf - sizeof(struct radv_opt_rdnss)) / sizeof(ip_addr); + int max_i = (bufend - *buf - sizeof(struct radv_opt_rdnss)) / sizeof(ip6_addr); int i = 0; if (max_i < 1) @@ -123,20 +123,19 @@ radv_prepare_rdnss(struct radv_iface *ifa, list *rdnss_list, char **buf, char *b else op->lifetime = htonl(rcf->lifetime); - while(NODE_VALID(rcf) && + while(NODE_VALID(rcf) && (rcf->lifetime == rcf_base->lifetime) && (rcf->lifetime_mult == rcf_base->lifetime_mult)) { if (i >= max_i) goto too_much; - op->servers[i] = rcf->server; - ipa_hton(op->servers[i]); + op->servers[i] = ip6_hton(rcf->server); i++; rcf = NODE_NEXT(rcf); } - + op->length = 1+2*i; *buf += 8 * op->length; } @@ -273,6 +272,9 @@ radv_prepare_ra(struct radv_iface *ifa) struct ifa *addr; WALK_LIST(addr, ifa->iface->addrs) { + if (addr->prefix.type != NET_IP6) + continue; + struct radv_prefix_config *pc; pc = radv_prefix_match(ifa, addr); @@ -288,7 +290,7 @@ radv_prepare_ra(struct radv_iface *ifa) struct radv_opt_prefix *op = (void *) buf; op->type = OPT_PREFIX; op->length = 4; - op->pxlen = addr->pxlen; + op->pxlen = net6_pxlen(&addr->prefix); op->flags = (pc->onlink ? OPT_PX_ONLINK : 0) | (pc->autonomous ? OPT_PX_AUTONOMOUS : 0); op->valid_lifetime = (ra->active || !pc->valid_lifetime_sensitive) ? @@ -296,8 +298,7 @@ radv_prepare_ra(struct radv_iface *ifa) op->preferred_lifetime = (ra->active || !pc->preferred_lifetime_sensitive) ? htonl(pc->preferred_lifetime) : 0; op->reserved = 0; - op->prefix = addr->prefix; - ipa_hton(op->prefix); + op->prefix = ip6_hton(net6_prefix(&addr->prefix)); buf += sizeof(*op); } diff --git a/proto/radv/radv.c b/proto/radv/radv.c index 2de89991..97713b95 100644 --- a/proto/radv/radv.c +++ b/proto/radv/radv.c @@ -143,7 +143,7 @@ find_lladdr(struct iface *iface) { struct ifa *a; WALK_LIST(a, iface->addrs) - if (a->scope == SCOPE_LINK) + if ((a->prefix.type == NET_IP6) && (a->scope == SCOPE_LINK)) return a; return NULL; diff --git a/proto/radv/radv.h b/proto/radv/radv.h index aede6a67..755009d4 100644 --- a/proto/radv/radv.h +++ b/proto/radv/radv.h @@ -82,8 +82,7 @@ struct radv_iface_config struct radv_prefix_config { node n; - ip_addr prefix; - int pxlen; + net_addr_ip6 prefix; u8 skip; /* Do not include this prefix to RA */ u8 onlink; /* Standard options from RFC 4261 */ @@ -99,7 +98,7 @@ struct radv_rdnss_config node n; u32 lifetime; /* Valid if lifetime_mult is 0 */ u16 lifetime_mult; /* Lifetime specified as multiple of max_ra_int */ - ip_addr server; /* IP address of recursive DNS server */ + ip6_addr server; /* IP address of recursive DNS server */ }; struct radv_dnssl_config diff --git a/proto/static/config.Y b/proto/static/config.Y index 182721b3..9e634803 100644 --- a/proto/static/config.Y +++ b/proto/static/config.Y @@ -52,11 +52,10 @@ static_proto: | static_proto stat_route stat_route_opt_list ';' { static_route_finish(); } ; -stat_route0: ROUTE prefix { +stat_route0: ROUTE net_any { this_srt = cfg_allocz(sizeof(struct static_route)); add_tail(&STATIC_CFG->other_routes, &this_srt->n); - this_srt->net = $2.addr; - this_srt->masklen = $2.len; + this_srt->net = $2; this_srt_last_cmd = &(this_srt->cmds); } ; @@ -72,7 +71,7 @@ stat_multipath1: this_srt_nh->use_bfd = -1; /* undefined */ } | stat_multipath1 WEIGHT expr { - this_srt_nh->masklen = $3 - 1; /* really */ + this_srt_nh->weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256"); } | stat_multipath1 BFD bool { diff --git a/proto/static/static.c b/proto/static/static.c index a11a9b6e..bc5f104f 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -26,7 +26,7 @@ * nodes (of dest RTD_NONE), which stores info about nexthops and are * connected to neighbor entries and neighbor notifications. Dummy * nodes are chained using mp_next, they aren't in other_routes list, - * and abuse some fields (masklen, if_name) for other purposes. + * and abuse if_name field for other purposes. * * The only other thing worth mentioning is that when asked for reconfiguration, * Static not only compares the two configurations, but it also calculates @@ -67,7 +67,7 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa) if (r->installed > 0) return; - DBG("Installing static route %I/%d, rtd=%d\n", r->net, r->masklen, r->dest); + DBG("Installing static route %N, rtd=%d\n", r->net, r->dest); bzero(&a, sizeof(a)); a.src = p->main_source; a.source = (r->dest == RTD_DEVICE) ? RTS_STATIC_DEVICE : RTS_STATIC; @@ -89,7 +89,7 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa) struct mpnh *nh = alloca(sizeof(struct mpnh)); nh->gw = r2->via; nh->iface = r2->neigh->iface; - nh->weight = r2->masklen; /* really */ + nh->weight = r2->weight; nh->next = NULL; *nhp = nh; nhp = &(nh->next); @@ -112,7 +112,7 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa) /* We skip rta_lookup() here */ - n = net_get_ipa(p->table, r->net, r->masklen); + n = net_get(p->table, r->net); e = rte_get_temp(&a); e->net = n; e->pflags = 0; @@ -135,8 +135,8 @@ static_remove(struct proto *p, struct static_route *r) if (!r->installed) return; - DBG("Removing static route %I/%d via %I\n", r->net, r->masklen, r->via); - n = net_find_ipa(p->table, r->net, r->masklen); + DBG("Removing static route %N via %I\n", r->net, r->via); + n = net_find(p->table, r->net); rte_update(p, n, NULL); r->installed = 0; } @@ -186,7 +186,7 @@ static_decide(struct static_config *cf, struct static_route *r) static void static_add(struct proto *p, struct static_config *cf, struct static_route *r) { - DBG("static_add(%I/%d,%d)\n", r->net, r->masklen, r->dest); + DBG("static_add(%N,%d)\n", r->net, r->dest); switch (r->dest) { case RTD_ROUTER: @@ -388,7 +388,7 @@ static_bfd_notify(struct bfd_request *req) static void static_dump_rt(struct static_route *r) { - debug("%-1I/%2d: ", r->net, r->masklen); + debug("%-1N: ", r->net); switch (r->dest) { case RTD_ROUTER: @@ -463,12 +463,6 @@ static_init(struct proto_config *c) } static inline int -static_same_net(struct static_route *x, struct static_route *y) -{ - return ipa_equal(x->net, y->net) && (x->masklen == y->masklen); -} - -static inline int static_same_dest(struct static_route *x, struct static_route *y) { if (x->dest != y->dest) @@ -486,7 +480,10 @@ static_same_dest(struct static_route *x, struct static_route *y) for (x = x->mp_next, y = y->mp_next; x && y; x = x->mp_next, y = y->mp_next) - if (!ipa_equal(x->via, y->via) || (x->via_if != y->via_if) || (x->use_bfd != y->use_bfd)) + if (!ipa_equal(x->via, y->via) || + (x->via_if != y->via_if) || + (x->use_bfd != y->use_bfd) || + (x->weight != y->weight)) return 0; return !x && !y; @@ -521,11 +518,11 @@ static_match(struct proto *p, struct static_route *r, struct static_config *n) r->neigh->data = NULL; WALK_LIST(t, n->iface_routes) - if (static_same_net(r, t)) + if (net_equal(r->net, t->net)) goto found; WALK_LIST(t, n->other_routes) - if (static_same_net(r, t)) + if (net_equal(r->net, t->net)) goto found; static_remove(p, r); @@ -659,13 +656,13 @@ static_show_rt(struct static_route *r) case RTDX_RECURSIVE: bsprintf(via, "recursive %I", r->via); break; default: bsprintf(via, "???"); } - cli_msg(-1009, "%I/%d %s%s%s", r->net, r->masklen, via, + cli_msg(-1009, "%N %s%s%s", r->net, via, r->bfd_req ? " (bfd)" : "", r->installed ? "" : " (dormant)"); struct static_route *r2; if (r->dest == RTD_MULTIPATH) for (r2 = r->mp_next; r2; r2 = r2->mp_next) - cli_msg(-1009, "\tvia %I%J weight %d%s%s", r2->via, r2->via_if, r2->masklen + 1, /* really */ + cli_msg(-1009, "\tvia %I%J weight %d%s%s", r2->via, r2->via_if, r2->weight + 1, r2->bfd_req ? " (bfd)" : "", r2->installed ? "" : " (dormant)"); } diff --git a/proto/static/static.h b/proto/static/static.h index 6b047234..51486e83 100644 --- a/proto/static/static.h +++ b/proto/static/static.h @@ -26,8 +26,7 @@ void static_init_config(struct static_config *); struct static_route { node n; struct static_route *chain; /* Next for the same neighbor */ - ip_addr net; /* Network we route */ - int masklen; /* Mask length */ + net_addr *net; /* Network we route */ int dest; /* Destination type (RTD_*) */ ip_addr via; /* Destination router */ struct iface *via_if; /* Destination iface, for link-local vias */ @@ -37,6 +36,7 @@ struct static_route { struct f_inst *cmds; /* List of commands for setting attributes */ int installed; /* Installed in rt table, -1 for reinstall */ int use_bfd; /* Configured to use BFD */ + int weight; /* Multipath next hop weight */ struct bfd_request *bfd_req; /* BFD request, if BFD is used */ }; diff --git a/sysdep/unix/krt.Y b/sysdep/unix/krt.Y index e036081d..e769ec0f 100644 --- a/sysdep/unix/krt.Y +++ b/sysdep/unix/krt.Y @@ -67,11 +67,10 @@ kif_item: /* Scan time of 0 means scan on startup only */ THIS_KIF->scan_time = $3; } - | PRIMARY text_or_none prefix_or_ipa { + | PRIMARY opttext net_or_ipa { struct kif_primary_item *kpi = cfg_alloc(sizeof (struct kif_primary_item)); - kpi->pattern = $2; - kpi->prefix = $3.addr; - kpi->pxlen = $3.len; + kpi->prefix = IPA_NONE; /* XXXX */ + kpi->pxlen = 0; /* XXXX */ add_tail(&THIS_KIF->primary, &kpi->n); } ; |