X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Ffib_types.c;h=5c5fd0b9823ff8d6b1e4ab395dbfafa14fac19c1;hb=06923b33a9507ee6a92facb770650fff93d89dff;hp=eab5ca22571a30baa0642822ddc42b13320ddb29;hpb=66edaf209fcfa618f42c0e6d21873a31de86b412;p=vpp.git diff --git a/src/vnet/fib/fib_types.c b/src/vnet/fib/fib_types.c index eab5ca22571..5c5fd0b9823 100644 --- a/src/vnet/fib/fib_types.c +++ b/src/vnet/fib/fib_types.c @@ -78,16 +78,15 @@ format_fib_mpls_label (u8 *s, va_list *ap) } void -fib_prefix_from_ip46_addr (const ip46_address_t *addr, +fib_prefix_from_ip46_addr (fib_protocol_t fproto, + const ip46_address_t *addr, fib_prefix_t *pfx) { - ASSERT(!ip46_address_is_zero(addr)); + ASSERT(FIB_PROTOCOL_MPLS != fproto); - pfx->fp_proto = ((ip46_address_is_ip4(addr) ? - FIB_PROTOCOL_IP4 : - FIB_PROTOCOL_IP6)); - pfx->fp_len = ((ip46_address_is_ip4(addr) ? - 32 : 128)); + pfx->fp_proto = fproto; + pfx->fp_len = ((FIB_PROTOCOL_IP4 == fproto) ? + 32 : 128); pfx->fp_addr = *addr; pfx->___fp___pad = 0; } @@ -541,6 +540,7 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) { fib_route_path_t *rpath = va_arg (*args, fib_route_path_t *); dpo_proto_t *payload_proto = va_arg (*args, void*); + dpo_proto_t explicit_proto = DPO_PROTO_NONE; u32 weight, preference, udp_encap_id, fi; mpls_label_t out_label; vnet_main_t *vnm; @@ -726,6 +726,14 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) vec_add1(rpath->frp_label_stack, fml); } } + else if (unformat (input, "ip4")) + { + explicit_proto = DPO_PROTO_IP4; + } + else if (unformat (input, "ip6")) + { + explicit_proto = DPO_PROTO_IP6; + } else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &rpath->frp_sw_if_index)) @@ -750,6 +758,9 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) } } + if (DPO_PROTO_NONE != explicit_proto) + *payload_proto = rpath->frp_proto = explicit_proto; + return (1); } @@ -785,3 +796,56 @@ fib_route_path_is_attached (const fib_route_path_t *rpath) } return (0); } + +static void +fib_prefix_ip4_addr_increment (fib_prefix_t *pfx) +{ + /* Calculate the addend based on the host length of address */ + u32 incr = 1ULL << (32 - pfx->fp_len); + ip4_address_t dst = (pfx->fp_addr).ip4; + dst.as_u32 = clib_host_to_net_u32 (incr + clib_net_to_host_u32 (dst.as_u32)); + pfx->fp_addr.ip4.as_u32 = dst.as_u32; +} + +static void +fib_prefix_ip6_addr_increment (fib_prefix_t *pfx) +{ + /* + * Calculate the addend based on the host length of address + * and which part(lower 64 bits or higher 64 bits) it lies + * in + */ + u32 host_len = 128 - pfx->fp_len; + u64 incr = 1ULL << ((host_len > 64) ? (host_len - 64) : host_len); + i32 bucket = (host_len < 64 ? 1 : 0); + ip6_address_t dst = (pfx->fp_addr).ip6; + u64 tmp = incr + clib_net_to_host_u64 (dst.as_u64[bucket]); + /* Handle overflow */ + if (bucket && (tmp < incr)) + { + dst.as_u64[1] = clib_host_to_net_u64 (tmp); + dst.as_u64[0] = clib_host_to_net_u64 (1ULL + clib_net_to_host_u64 (dst.as_u64[0])); + } + else + dst.as_u64[bucket] = clib_host_to_net_u64 (tmp); + + pfx->fp_addr.ip6.as_u128 = dst.as_u128; +} + +/* + * Increase IPv4/IPv6 address according to the prefix length + */ +void fib_prefix_increment (fib_prefix_t *pfx) +{ + switch (pfx->fp_proto) + { + case FIB_PROTOCOL_IP4: + fib_prefix_ip4_addr_increment (pfx); + break; + case FIB_PROTOCOL_IP6: + fib_prefix_ip6_addr_increment (pfx); + break; + case FIB_PROTOCOL_MPLS: + break; + } +}