From c7e7819ad5c152168a5f1a217c3b72043fd48797 Mon Sep 17 00:00:00 2001 From: Chenmin Sun Date: Fri, 4 Sep 2020 06:50:22 +0800 Subject: flow: Add API implementation of IP4/IP6, IP4_VXLAN/IP6_VXLAN This patch adds the API handler implementation of the below flows: FLOW_TYPE_IP4, FLOW_TYPE_IP6, FLOW_TYPE_IP4_VXLAN, FLOW_TYPE_IP6_VXLAN Type: feature Signed-off-by: Chenmin Sun Change-Id: I62e1c466b46f940180e957c859d122086aa22f1c --- src/vnet/flow/FEATURE.yaml | 4 ++++ src/vnet/flow/flow.api | 2 +- src/vnet/flow/flow_api.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) (limited to 'src/vnet') diff --git a/src/vnet/flow/FEATURE.yaml b/src/vnet/flow/FEATURE.yaml index cd86429557c..a26571c35e8 100644 --- a/src/vnet/flow/FEATURE.yaml +++ b/src/vnet/flow/FEATURE.yaml @@ -4,6 +4,8 @@ maintainer: Damjan Marion features: - Four APIs are provided - flow_add, flow_del, flow_enable and flow_disable - The below flow types are currently supported: + - FLOW_TYPE_IP4, + - FLOW_TYPE_IP6, - FLOW_TYPE_IP4_N_TUPLE, - FLOW_TYPE_IP6_N_TUPLE, - FLOW_TYPE_IP4_N_TUPLE_TAGGED, @@ -11,6 +13,8 @@ features: - FLOW_TYPE_IP4_L2TPV3OIP, - FLOW_TYPE_IP4_IPSEC_ESP, - FLOW_TYPE_IP4_IPSEC_AH, + - FLOW_TYPE_IP4_VXLAN, + - FLOW_TYPE_IP6_VXLAN, - FLOW_TYPE_IP4_GTPC, - FLOW_TYPE_IP4_GTPU - The below flow actions can be specified for the flows: diff --git a/src/vnet/flow/flow.api b/src/vnet/flow/flow.api index b819847e998..7bb21cdcd72 100644 --- a/src/vnet/flow/flow.api +++ b/src/vnet/flow/flow.api @@ -13,7 +13,7 @@ * limitations under the License. */ -option version = "0.0.1"; +option version = "0.0.2"; import "vnet/interface_types.api"; import "vnet/ip/ip_types.api"; diff --git a/src/vnet/flow/flow_api.c b/src/vnet/flow/flow_api.c index b24c8510be5..4d0c536f113 100644 --- a/src/vnet/flow/flow_api.c +++ b/src/vnet/flow/flow_api.c @@ -82,6 +82,24 @@ port_and_mask_convert (vl_api_ip_port_and_mask_t * vl_api_port, vnet_port->mask = ntohs (vl_api_port->mask); } +static inline void +ipv4_flow_convert (vl_api_flow_ip4_t *vl_api_flow, vnet_flow_ip4_t *f) +{ + ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); + ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); + + protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); +} + +static void +ipv6_flow_convert (vl_api_flow_ip6_t *vl_api_flow, vnet_flow_ip6_t *f) +{ + ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); + ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); + + protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); +} + static inline void ipv4_n_tuple_flow_convert (vl_api_flow_ip4_n_tuple_t * vl_api_flow, vnet_flow_ip4_n_tuple_t * f) @@ -157,6 +175,34 @@ ipv4_ipsec_ah_flow_convert (vl_api_flow_ip4_ipsec_ah_t * vl_api_flow, f->spi = ntohl (vl_api_flow->spi); } +static inline void +ipv4_vxlan_flow_convert (vl_api_flow_ip4_vxlan_t *vl_api_flow, + vnet_flow_ip4_vxlan_t *f) +{ + ipv4_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); + ipv4_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); + protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); + + port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); + port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); + + f->vni = ntohs (vl_api_flow->vni); +} + +static inline void +ipv6_vxlan_flow_convert (vl_api_flow_ip6_vxlan_t *vl_api_flow, + vnet_flow_ip6_vxlan_t *f) +{ + ipv6_addr_and_mask_convert (&vl_api_flow->src_addr, &f->src_addr); + ipv6_addr_and_mask_convert (&vl_api_flow->dst_addr, &f->dst_addr); + protocol_and_mask_convert (&vl_api_flow->protocol, &f->protocol); + + port_and_mask_convert (&vl_api_flow->src_port, &f->src_port); + port_and_mask_convert (&vl_api_flow->dst_port, &f->dst_port); + + f->vni = ntohs (vl_api_flow->vni); +} + static inline void ipv4_gtpu_flow_convert (vl_api_flow_ip4_gtpu_t * vl_api_flow, vnet_flow_ip4_gtpu_t * f) @@ -207,6 +253,12 @@ vl_api_flow_add_t_handler (vl_api_flow_add_t * mp) switch (flow.type) { + case VNET_FLOW_TYPE_IP4: + ipv4_flow_convert (&f->flow.ip4, &flow.ip4); + break; + case VNET_FLOW_TYPE_IP6: + ipv6_flow_convert (&f->flow.ip6, &flow.ip6); + break; case VNET_FLOW_TYPE_IP4_N_TUPLE: ipv4_n_tuple_flow_convert (&f->flow.ip4_n_tuple, &flow.ip4_n_tuple); break; @@ -232,6 +284,12 @@ vl_api_flow_add_t_handler (vl_api_flow_add_t * mp) case VNET_FLOW_TYPE_IP4_IPSEC_AH: ipv4_ipsec_ah_flow_convert (&f->flow.ip4_ipsec_ah, &flow.ip4_ipsec_ah); break; + case VNET_FLOW_TYPE_IP4_VXLAN: + ipv4_vxlan_flow_convert (&f->flow.ip4_vxlan, &flow.ip4_vxlan); + break; + case VNET_FLOW_TYPE_IP6_VXLAN: + ipv6_vxlan_flow_convert (&f->flow.ip6_vxlan, &flow.ip6_vxlan); + break; case VNET_FLOW_TYPE_IP4_GTPU: ipv4_gtpu_flow_convert (&f->flow.ip4_gtpu, &flow.ip4_gtpu); break; -- cgit 1.2.3-korg