X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Flisp-cp%2Flisp_types.c;h=a706832a24978e8901554a77fadb998b8211b6eb;hb=ad9d528;hp=85cefae05abef2c917068b671ed1580edafd8c43;hpb=d5a65db98d66c66b03b057ac568be05f2456f73c;p=vpp.git diff --git a/src/vnet/lisp-cp/lisp_types.c b/src/vnet/lisp-cp/lisp_types.c index 85cefae05ab..a706832a249 100644 --- a/src/vnet/lisp-cp/lisp_types.c +++ b/src/vnet/lisp-cp/lisp_types.c @@ -31,16 +31,28 @@ typedef int (*cmp_fct) (void *, void *); size_to_write_fct size_to_write_fcts[GID_ADDR_TYPES] = { ip_prefix_size_to_write, lcaf_size_to_write, mac_size_to_write, - sd_size_to_write, nsh_size_to_write + sd_size_to_write, nsh_size_to_write, 0 /* arp */ , no_addr_size_to_write }; + serdes_fct write_fcts[GID_ADDR_TYPES] = - { ip_prefix_write, lcaf_write, mac_write, sd_write, nsh_write }; + { ip_prefix_write, lcaf_write, mac_write, sd_write, nsh_write, 0 /* arp */ , + no_addr_write +}; + cast_fct cast_fcts[GID_ADDR_TYPES] = - { ip_prefix_cast, lcaf_cast, mac_cast, sd_cast, nsh_cast }; + { ip_prefix_cast, lcaf_cast, mac_cast, sd_cast, nsh_cast, 0 /* arp */ , + no_addr_cast +}; + addr_len_fct addr_len_fcts[GID_ADDR_TYPES] = - { ip_prefix_length, lcaf_length, mac_length, sd_length, nsh_length }; + { ip_prefix_length, lcaf_length, mac_length, sd_length, nsh_length, + 0 /* arp */ , no_addr_length +}; + copy_fct copy_fcts[GID_ADDR_TYPES] = - { ip_prefix_copy, lcaf_copy, mac_copy, sd_copy, nsh_copy }; + { ip_prefix_copy, lcaf_copy, mac_copy, sd_copy, nsh_copy, 0 /* arp */ , + no_addr_copy +}; #define foreach_lcaf_type \ _(1, no_addr) \ @@ -55,7 +67,12 @@ copy_fct copy_fcts[GID_ADDR_TYPES] = _(0, NULL) \ _(0, NULL) \ _(0, NULL) \ - _(1, sd) + _(1, sd) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(1, nsh) #define _(cond, name) \ u16 name ## _write (u8 * p, void * a); \ @@ -148,7 +165,7 @@ unformat_ip_address (unformat_input_t * input, va_list * args) { ip_address_t *a = va_arg (*args, ip_address_t *); - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (a))) ip_addr_version (a) = IP4; else if (unformat_user (input, unformat_ip6_address, &ip_addr_v6 (a))) @@ -186,22 +203,6 @@ unformat_ip_prefix (unformat_input_t * input, va_list * args) return 1; } -uword -unformat_mac_address (unformat_input_t * input, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5]); -} - -u8 * -format_mac_address (u8 * s, va_list * args) -{ - u8 *a = va_arg (*args, u8 *); - return format (s, "%02x:%02x:%02x:%02x:%02x:%02x", - a[0], a[1], a[2], a[3], a[4], a[5]); -} - uword unformat_nsh_address (unformat_input_t * input, va_list * args) { @@ -216,6 +217,13 @@ format_nsh_address (u8 * s, va_list * args) return format (s, "SPI:%d SI:%d", a->spi, a->si); } +u8 * +format_fid_nsh_address (u8 * s, va_list * args) +{ + u32 *a = va_arg (*args, u32 *); + return format (s, "SPI:%d SI:%d", *a >> 8, *a & 0xff); +} + u8 * format_fid_address (u8 * s, va_list * args) { @@ -228,7 +236,7 @@ format_fid_address (u8 * s, va_list * args) case FID_ADDR_MAC: return format (s, "%U", format_mac_address, &fid_addr_mac (a)); case FID_ADDR_NSH: - return format (s, "%U", format_nsh_address, &fid_addr_nsh (a)); + return format (s, "%U", format_fid_nsh_address, &fid_addr_nsh (a)); default: clib_warning ("Can't format fid address type %d!", fid_addr_type (a)); @@ -254,11 +262,13 @@ format_gid_address (u8 * s, va_list * args) case GID_ADDR_MAC: return format (s, "[%d] %U", gid_address_vni (a), format_mac_address, &gid_address_mac (a)); + case GID_ADDR_ARP: + case GID_ADDR_NDP: + return format (s, "[%d, %U]", gid_address_arp_ndp_bd (a), + format_ip_address, &gid_address_arp_ndp_ip (a)); case GID_ADDR_NSH: return format (s, "%U", format_nsh_address, &gid_address_nsh (a)); - case GID_ADDR_ARP: - return format (s, "[%d, %U]", gid_address_arp_bd (a), - format_ip4_address, &gid_address_arp_ip4 (a)); + default: clib_warning ("Can't format gid type %d", type); return 0; @@ -287,7 +297,7 @@ unformat_fid_address (unformat_input_t * i, va_list * args) else if (unformat (i, "%U", unformat_nsh_address, &nsh)) { fid_addr_type (a) = FID_ADDR_NSH; - nsh_copy (&fid_addr_nsh (a), mac); + nsh_copy (&fid_addr_nsh (a), &nsh); } else return 0; @@ -329,9 +339,9 @@ unformat_gid_address (unformat_input_t * input, va_list * args) fid_address_t sim1, sim2; nsh_t nsh; - memset (&ippref, 0, sizeof (ippref)); - memset (&sim1, 0, sizeof (sim1)); - memset (&sim2, 0, sizeof (sim2)); + clib_memset (&ippref, 0, sizeof (ippref)); + clib_memset (&sim1, 0, sizeof (sim1)); + clib_memset (&sim2, 0, sizeof (sim2)); if (unformat (input, "%U|%U", unformat_fid_address, &sim1, unformat_fid_address, &sim2)) @@ -673,6 +683,38 @@ do { \ dst += _sum; \ } while (0); +void +nsh_free (void *a) +{ + /* nothing to do */ +} + +u16 +nsh_parse (u8 * p, void *a) +{ + lcaf_spi_hdr_t *h = (lcaf_spi_hdr_t *) p; + gid_address_t *g = a; + + gid_address_type (g) = GID_ADDR_NSH; + gid_address_nsh_spi (g) = clib_net_to_host_u32 (LCAF_SPI_SI (h)) >> 8; + gid_address_nsh_si (g) = (u8) clib_net_to_host_u32 (LCAF_SPI_SI (h)); + + return sizeof (lcaf_spi_hdr_t); +} + +int +nsh_cmp (void *a1, void *a2) +{ + nsh_t *n1 = a1; + nsh_t *n2 = a2; + + if (n1->spi != n2->spi) + return 1; + if (n1->si != n2->si) + return 1; + return 0; +} + u16 sd_parse (u8 * p, void *a) { @@ -802,7 +844,7 @@ gid_address_free (gid_address_t * a) void gid_address_from_ip (gid_address_t * g, ip_address_t * ip) { - memset (g, 0, sizeof (g[0])); + clib_memset (g, 0, sizeof (g[0])); ip_address_set (&gid_address_ip (g), ip, ip_addr_version (ip)); gid_address_ippref_len (g) = 32; } @@ -829,8 +871,8 @@ ip_address_copy (ip_address_t * dst, const ip_address_t * src) { if (IP4 == ip_addr_version (src)) { - /* don't copy any garbe from the union */ - memset (dst, 0, sizeof (*dst)); + /* don't copy any garbage from the union */ + clib_memset (dst, 0, sizeof (*dst)); dst->ip.v4 = src->ip.v4; dst->version = IP4; } @@ -899,7 +941,7 @@ ip_prefix_normalize_ip6 (ip6_address_t * ip6, u8 preflen) ASSERT (ip6); - memset (mask_6, 0, sizeof (mask_6)); + clib_memset (mask_6, 0, sizeof (mask_6)); if (128 <= preflen) { @@ -1094,6 +1136,12 @@ mac_cast (gid_address_t * a) return &gid_address_mac (a); } +void * +no_addr_cast (gid_address_t * a) +{ + return (void *) a; +} + void * sd_cast (gid_address_t * a) { @@ -1130,7 +1178,7 @@ lcaf_write (u8 * p, void *a) *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); size += sizeof (u16); - memset (h, 0, sizeof (h[0])); + clib_memset (h, 0, sizeof (h[0])); LCAF_TYPE (h) = type; u16 lcaf_len = (*lcaf_body_length_fcts[type]) (lcaf); LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); @@ -1195,7 +1243,7 @@ sd_write (u8 * p, void *a) *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); size += sizeof (u16); - memset (h, 0, sizeof (h[0])); + clib_memset (h, 0, sizeof (h[0])); LCAF_TYPE (h) = LCAF_SOURCE_DEST; u16 lcaf_len = sizeof (lcaf_src_dst_hdr_t) + fid_addr_size_to_write (&sd_src (sd)) @@ -1205,7 +1253,7 @@ sd_write (u8 * p, void *a) clib_memcpy (p + size, h, sizeof (h[0])); size += sizeof (h[0]); - memset (&sd_hdr, 0, sizeof (sd_hdr)); + clib_memset (&sd_hdr, 0, sizeof (sd_hdr)); LCAF_SD_SRC_ML (&sd_hdr) = fid_address_length (&sd_src (sd)); LCAF_SD_DST_ML (&sd_hdr) = fid_address_length (&sd_dst (sd)); clib_memcpy (p + size, &sd_hdr, sizeof (sd_hdr)); @@ -1227,8 +1275,33 @@ sd_write (u8 * p, void *a) u16 nsh_write (u8 * p, void *a) { - clib_warning ("not done"); - return 0; + lcaf_spi_hdr_t spi; + lcaf_hdr_t lcaf; + gid_address_t *g = a; + u16 size = 0; + + ASSERT (gid_address_type (g) == GID_ADDR_NSH); + + clib_memset (&lcaf, 0, sizeof (lcaf)); + clib_memset (&spi, 0, sizeof (spi)); + + LCAF_TYPE (&lcaf) = LCAF_NSH; + LCAF_LENGTH (&lcaf) = clib_host_to_net_u16 (sizeof (lcaf_spi_hdr_t)); + + u32 s = clib_host_to_net_u32 (gid_address_nsh_spi (g) << 8 | + gid_address_nsh_si (g)); + LCAF_SPI_SI (&spi) = s; + + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); + size += sizeof (u16); + + clib_memcpy (p + size, &lcaf, sizeof (lcaf)); + size += sizeof (lcaf); + + clib_memcpy (p + size, &spi, sizeof (spi)); + size += sizeof (spi); + + return size; } u16 @@ -1241,7 +1314,7 @@ vni_write (u8 * p, void *a) /* put lcaf header */ *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); size += sizeof (u16); - memset (h, 0, sizeof (h[0])); + clib_memset (h, 0, sizeof (h[0])); LCAF_TYPE (h) = LCAF_INSTANCE_ID; u16 lcaf_len = sizeof (u32) /* Instance ID size */ + gid_address_size_to_put_no_vni (g); @@ -1354,7 +1427,7 @@ mac_size_to_write (void *a) u16 nsh_size_to_write (void *a) { - return sizeof (u16) + 4; + return sizeof (u16) + sizeof (lcaf_hdr_t) + sizeof (lcaf_spi_hdr_t); } u8 @@ -1581,6 +1654,9 @@ gid_address_cmp (gid_address_t * a1, gid_address_t * a2) case GID_ADDR_SRC_DST: cmp = sd_cmp (&gid_address_sd (a1), &gid_address_sd (a2)); break; + case GID_ADDR_NSH: + cmp = nsh_cmp (&gid_address_nsh (a1), &gid_address_nsh (a2)); + break; default: break; } @@ -1650,7 +1726,7 @@ locator_free (locator_t * l) void build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst) { - memset (sd, 0, sizeof (*sd)); + clib_memset (sd, 0, sizeof (*sd)); gid_address_type (sd) = GID_ADDR_SRC_DST; gid_address_vni (sd) = gid_address_vni (dst); gid_address_vni_mask (sd) = gid_address_vni_mask (dst);