diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2014-10-24 11:11:43 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2014-10-24 11:11:43 +0200 |
commit | 88a183c6c9a2b86b52f67e87bbc8b7edd32670c6 (patch) | |
tree | b1348b71e69f9ed0d919a4792549026c9e31b092 /proto | |
parent | f8fefde318c6248ad94e7b6d60155deed9ab8eed (diff) |
Integrated IP functions.
Diffstat (limited to 'proto')
-rw-r--r-- | proto/bgp/attrs.c | 2 | ||||
-rw-r--r-- | proto/bgp/bgp.c | 12 | ||||
-rw-r--r-- | proto/bgp/config.Y | 2 | ||||
-rw-r--r-- | proto/bgp/packets.c | 8 | ||||
-rw-r--r-- | proto/ospf/ospf.h | 33 | ||||
-rw-r--r-- | proto/ospf/packet.c | 3 | ||||
-rw-r--r-- | proto/ospf/rt.c | 4 | ||||
-rw-r--r-- | proto/ospf/topology.c | 2 | ||||
-rw-r--r-- | proto/radv/packets.c | 4 | ||||
-rw-r--r-- | proto/radv/radv.h | 3 | ||||
-rw-r--r-- | proto/rip/rip.c | 10 |
11 files changed, 29 insertions, 54 deletions
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 1d37bfd7..a091ed1e 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -991,7 +991,7 @@ bgp_create_attrs(struct bgp_proto *p, rte *e, ea_list **attrs, struct linpool *p if (p->cf->next_hop_self || rta->dest != RTD_ROUTER || ipa_equal(rta->gw, IPA_NONE) || - ipa_has_link_scope(rta->gw) || + ipa_is_link_local(rta->gw) || (!p->is_internal && !p->cf->next_hop_keep && (!p->neigh || (rta->iface != p->neigh->iface)))) set_next_hop(z, p->source_addr); diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index e2339112..27825d7f 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -689,7 +689,7 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c s->password = p->cf->password; s->tx_hook = bgp_connected; BGP_TRACE(D_EVENTS, "Connecting to %I%J from local address %I%J", s->daddr, p->cf->iface, - s->saddr, ipa_has_link_scope(s->saddr) ? s->iface : NULL); + s->saddr, ipa_is_link_local(s->saddr) ? s->iface : NULL); bgp_setup_conn(p, conn); bgp_setup_sk(conn, s); bgp_conn_set_state(conn, BS_CONNECT); @@ -735,7 +735,7 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED) { struct bgp_proto *p = (struct bgp_proto *) pc->proto; if (ipa_equal(p->cf->remote_ip, sk->daddr) && - (!ipa_has_link_scope(sk->daddr) || (p->cf->iface == sk->iface))) + (!ipa_is_link_local(sk->daddr) || (p->cf->iface == sk->iface))) { /* We are in proper state and there is no other incoming connection */ int acc = (p->p.proto_state == PS_START || p->p.proto_state == PS_UP) && @@ -750,7 +750,7 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED) } BGP_TRACE(D_EVENTS, "Incoming connection from %I%J (port %d) %s", - sk->daddr, ipa_has_link_scope(sk->daddr) ? sk->iface : NULL, + sk->daddr, ipa_is_link_local(sk->daddr) ? sk->iface : NULL, sk->dport, acc ? "accepted" : "rejected"); if (!acc) @@ -779,7 +779,7 @@ bgp_incoming_connection(sock *sk, int dummy UNUSED) } log(L_WARN "BGP: Unexpected connect from unknown address %I%J (port %d)", - sk->daddr, ipa_has_link_scope(sk->daddr) ? sk->iface : NULL, sk->dport); + sk->daddr, ipa_is_link_local(sk->daddr) ? sk->iface : NULL, sk->dport); reject: rfree(sk); return 0; @@ -1169,8 +1169,8 @@ bgp_check_config(struct bgp_config *c) if (c->multihop && (c->gw_mode == GW_DIRECT)) cf_error("Multihop BGP cannot use direct gateway mode"); - if (c->multihop && (ipa_has_link_scope(c->remote_ip) || - ipa_has_link_scope(c->source_addr))) + if (c->multihop && (ipa_is_link_local(c->remote_ip) || + ipa_is_link_local(c->source_addr))) cf_error("Multihop BGP cannot be used with link-local addresses"); if (c->multihop && c->bfd && ipa_zero(c->source_addr)) diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index 8e0b2412..c8345530 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -63,7 +63,7 @@ bgp_proto: | bgp_proto NEIGHBOR ipa ipa_scope ipa_port AS expr ';' { if (ipa_nonzero(BGP_CFG->remote_ip)) cf_error("Only one neighbor per BGP instance is allowed"); - if (!ipa_has_link_scope($3) != !$4) + if (!ipa_is_link_local($3) != !$4) cf_error("Link-local address and interface scope must be used together"); BGP_CFG->remote_ip = $3; diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 0b9de8c1..69646c7d 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -69,8 +69,8 @@ mrt_put_bgp4_hdr(byte *buf, struct bgp_conn *conn, int as4) put_u16(buf+0, (p->neigh && p->neigh->iface) ? p->neigh->iface->index : 0); put_u16(buf+2, BGP_AF); buf+=4; - buf = ipa_put_addr(buf, conn->sk ? conn->sk->daddr : IPA_NONE); - buf = ipa_put_addr(buf, conn->sk ? conn->sk->saddr : IPA_NONE); + buf = put_ipa(buf, conn->sk ? conn->sk->daddr : IPA_NONE); + buf = put_ipa(buf, conn->sk ? conn->sk->saddr : IPA_NONE); return buf; } @@ -522,7 +522,7 @@ bgp_create_update(struct bgp_conn *conn, byte *buf) *tmp++ = BGP_AF_IPV6; *tmp++ = 1; - if (ipa_has_link_scope(ip)) + if (ipa_is_link_local(ip)) ip = IPA_NONE; if (ipa_nonzero(ip_ll)) @@ -1034,7 +1034,7 @@ bgp_set_next_hop(struct bgp_proto *p, rta *a) int second = (nh->u.ptr->length == NEXT_HOP_LENGTH) && ipa_nonzero(nexthop[1]); /* First address should not be link-local, but may be zero in direct mode */ - if (ipa_has_link_scope(*nexthop)) + if (ipa_is_link_local(*nexthop)) *nexthop = IPA_NONE; #else int second = 0; diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index 6df5df08..e535287c 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -37,36 +37,9 @@ #endif -#define IP4_MIN_MTU 576 -#define IP6_MIN_MTU 1280 - -#define IP4_OSPF_ALL_ROUTERS ipa_build4(224, 0, 0, 5) -#define IP4_OSPF_DES_ROUTERS ipa_build4(224, 0, 0, 6) - -#define IP6_OSPF_ALL_ROUTERS ipa_build6(0xFF020000, 0, 0, 5) -#define IP6_OSPF_DES_ROUTERS ipa_build6(0xFF020000, 0, 0, 6) - #ifdef IPV6 -#define ip4_addr u32 -#define ip6_addr ip_addr -#define _MI6(x1,x2,x3,x4) _MI(x1, x2, x3, x4) -#define ipa_is_link_local(x) ipa_has_link_scope(x) -#define ipa_from_u32(x) _MI6(0,0,0xffff,x) -#define ipa_to_u32(x) _I3(x) -#define ipa_build4(a,b,c,d) IPA_NONE -#define ipa_build6(a,b,c,d) _MI6(a,b,c,d) #define OSPF_IS_V2 0 #else -#define ip4_addr u32 -#define ip6_addr ip_addr -#define _I0(X) 0 -#define _I1(X) 0 -#define _I2(X) 0 -#define _I3(X) 0 -#define _MI6(x1,x2,x3,x4) IPA_NONE -#define ipa_is_link_local(x) 0 -#define ipa_build4(a,b,c,d) _MI(((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) -#define ipa_build6(a,b,c,d) IPA_NONE #define OSPF_IS_V2 1 #endif @@ -744,10 +717,12 @@ lsa_net_count(struct ospf_lsa_header *lsa) #define ipa_from_rid(x) ipa_from_u32(x) #define ipa_to_rid(x) ipa_to_u32(x) - #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4) #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32) +/* FIXME: these four functions should be significantly redesigned w.r.t. integration, + also should be named as ospf3_* instead of *_ipv6_* */ + static inline u32 * lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest) { @@ -787,6 +762,7 @@ lsa_get_ipv6_addr(u32 *buf, ip_addr *addr) static inline u32 * put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh) { +#ifdef IPV6 *buf++ = ((pxlen << 24) | (pxopts << 16) | lh); if (pxlen > 0) @@ -797,6 +773,7 @@ put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh) *buf++ = _I2(addr); if (pxlen > 96) *buf++ = _I3(addr); +#endif return buf; } diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c index 2814712d..a545c7fd 100644 --- a/proto/ospf/packet.c +++ b/proto/ospf/packet.c @@ -265,7 +265,8 @@ ospf_rx_hook(sock *sk, int len) } /* Second, we check packet length, checksum, and the protocol version */ - struct ospf_packet *pkt = (struct ospf_packet *) ip_skip_header(sk->rbuf, &len); + struct ospf_packet *pkt = (void *) sk_rx_buffer(sk, &len); + if (pkt == NULL) DROP("bad IP header", len); diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 08f90b49..b616c0d1 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -1822,10 +1822,10 @@ calc_next_hop(struct ospf_area *oa, struct top_hash_entry *en, struct ospf_lsa_link *llsa = lhe->lsa_body; - if (ipa_zero(llsa->lladdr)) + if (ip6_zero(llsa->lladdr)) return NULL; - return new_nexthop(p, llsa->lladdr, pn->iface, pn->weight); + return new_nexthop(p, ipa_from_ip6(llsa->lladdr), pn->iface, pn->weight); } } diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index 15ba013a..42bf9c45 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -1319,7 +1319,7 @@ prepare_link_lsa_body(struct ospf_proto *p, struct ospf_iface *ifa) ASSERT(p->lsab_used == 0); ll = lsab_allocz(p, sizeof(struct ospf_lsa_link)); ll->options = ifa->oa->options | (ifa->priority << 24); - ll->lladdr = ifa->addr->ip; + ll->lladdr = ipa_to_ip6(ifa->addr->ip); ll = NULL; /* buffer might be reallocated later */ struct ifa *a; diff --git a/proto/radv/packets.c b/proto/radv/packets.c index ef869722..3862af8d 100644 --- a/proto/radv/packets.c +++ b/proto/radv/packets.c @@ -343,7 +343,7 @@ radv_send_ra(struct radv_iface *ifa, int shutdown) } RADV_TRACE(D_PACKETS, "Sending RA via %s", ifa->iface->name); - sk_send_to(ifa->sk, ifa->plen, AllNodes, 0); + sk_send_to(ifa->sk, ifa->plen, IP6_ALL_NODES, 0); } @@ -432,7 +432,7 @@ radv_sk_open(struct radv_iface *ifa) if (sk_setup_multicast(sk) < 0) goto err; - if (sk_join_group(sk, AllRouters) < 0) + if (sk_join_group(sk, IP6_ALL_ROUTERS) < 0) goto err; ifa->sk = sk; diff --git a/proto/radv/radv.h b/proto/radv/radv.h index bb80d65f..48ba9c1a 100644 --- a/proto/radv/radv.h +++ b/proto/radv/radv.h @@ -26,9 +26,6 @@ #define ICMPV6_PROTO 58 -#define AllNodes _MI(0xFF020000, 0, 0, 1) /* FF02::1 */ -#define AllRouters _MI(0xFF020000, 0, 0, 2) /* FF02::2 */ - #define ICMPV6_RS 133 #define ICMPV6_RA 134 diff --git a/proto/rip/rip.c b/proto/rip/rip.c index bc9ffc5f..a0c28e72 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -305,7 +305,7 @@ advertise_entry( struct proto *p, struct rip_block *b, ip_addr whotoldme, struct A.flags = 0; #ifndef IPV6 A.gw = ipa_nonzero(b->nexthop) ? b->nexthop : whotoldme; - pxlen = ipa_mklen(b->netmask); + pxlen = ipa_masklen(b->netmask); #else /* FIXME: next hop is in other packet for v6 */ A.gw = whotoldme; @@ -365,7 +365,7 @@ process_block( struct proto *p, struct rip_block *block, ip_addr whotoldme, stru #ifndef IPV6 metric = ntohl( block->metric ); - pxlen = ipa_mklen(block->netmask); + pxlen = ipa_masklen(block->netmask); #else metric = block->metric; pxlen = block->pxlen; @@ -447,7 +447,7 @@ rip_process_packet( struct proto *p, struct rip_packet *packet, int num, ip_addr ipa_ntoh( block->netmask ); ipa_ntoh( block->nexthop ); if (packet->heading.version == RIP_V1) /* FIXME (nonurgent): switch to disable this? */ - block->netmask = ipa_class_mask(block->network); + block->netmask = ip4_class_mask(ipa_to_ip4(block->network)); #endif process_block( p, block, whotoldme, iface ); } @@ -721,7 +721,7 @@ new_iface(struct proto *p, struct iface *new, unsigned long flags, struct iface_ #ifndef IPV6 rif->sock->daddr = ipa_from_u32(0xe0000009); #else - rif->sock->daddr = ipa_build(0xff020000, 0, 0, 9); + rif->sock->daddr = IP6_RIP_ROUTERS; #endif } else { rif->sock->daddr = new->addr->brd; @@ -812,7 +812,7 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *iface) #ifndef IPV6 lock->addr = ipa_from_u32(0xe0000009); #else - ip_pton("FF02::9", &lock->addr); + lock->addr = IP6_RIP_ROUTERS; #endif else lock->addr = iface->addr->brd; |