[ovs-dev] [PATCH v2 10/15] netdev-vport: Introduce ip_build_header()
Pravin B Shelar
pshelar at ovn.org
Fri Apr 22 01:54:25 UTC 2016
This function can be used to build varius tunnel headers.
Signed-off-by: Pravin B Shelar <pshelar at ovn.org>
---
lib/netdev-native-tnl.c | 35 +++--------------------------------
lib/netdev-native-tnl.h | 25 +++++++++++++++++++++++++
2 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c
index d28cfbf..9c2dc7e 100644
--- a/lib/netdev-native-tnl.c
+++ b/lib/netdev-native-tnl.c
@@ -249,27 +249,10 @@ udp_build_header(struct netdev_tunnel_config *tnl_cfg,
struct ovs_action_push_tnl *data,
unsigned int *hlen)
{
- struct ip_header *ip;
- struct ovs_16aligned_ip6_hdr *ip6;
struct udp_header *udp;
bool is_ipv6;
- *hlen = sizeof(struct eth_header);
-
- is_ipv6 = is_header_ipv6(data->header);
-
- if (is_ipv6) {
- ip6 = ipv6_hdr(data->header);
- ip6->ip6_nxt = IPPROTO_UDP;
- udp = (struct udp_header *) (ip6 + 1);
- *hlen += IPV6_HEADER_LEN;
- } else {
- ip = ip_hdr(data->header);
- ip->ip_proto = IPPROTO_UDP;
- udp = (struct udp_header *) (ip + 1);
- *hlen += IP_HEADER_LEN;
- }
-
+ udp = ip_build_header(data, IPPROTO_UDP, hlen, &is_ipv6);
udp->udp_dst = tnl_cfg->dst_port;
if (is_ipv6 || tnl_flow->tunnel.flags & FLOW_TNL_F_CSUM) {
@@ -403,28 +386,16 @@ netdev_gre_build_header(const struct netdev *netdev,
{
struct netdev_vport *dev = netdev_vport_cast(netdev);
struct netdev_tunnel_config *tnl_cfg;
- struct ip_header *ip;
- struct ovs_16aligned_ip6_hdr *ip6;
struct gre_base_hdr *greh;
ovs_16aligned_be32 *options;
- int hlen;
+ unsigned int hlen, offset;
bool is_ipv6;
- is_ipv6 = is_header_ipv6(data->header);
-
/* XXX: RCUfy tnl_cfg. */
ovs_mutex_lock(&dev->mutex);
tnl_cfg = &dev->tnl_cfg;
- if (is_ipv6) {
- ip6 = ipv6_hdr(data->header);
- ip6->ip6_nxt = IPPROTO_GRE;
- greh = (struct gre_base_hdr *) (ip6 + 1);
- } else {
- ip = ip_hdr(data->header);
- ip->ip_proto = IPPROTO_GRE;
- greh = (struct gre_base_hdr *) (ip + 1);
- }
+ greh = ip_build_header(data, IPPROTO_GRE, &offset, &is_ipv6);
greh->protocol = htons(ETH_TYPE_TEB);
greh->flags = 0;
diff --git a/lib/netdev-native-tnl.h b/lib/netdev-native-tnl.h
index dbe6bd0..a0dfa8c 100644
--- a/lib/netdev-native-tnl.h
+++ b/lib/netdev-native-tnl.h
@@ -82,6 +82,31 @@ ipv6_hdr(void *eth)
return (void *)((char *)eth + sizeof (struct eth_header));
}
+static inline void *
+ip_build_header(struct ovs_action_push_tnl *data,
+ uint8_t next_proto,
+ unsigned int *hlen,
+ bool *is_ipv6)
+{
+ *hlen = sizeof(struct eth_header);
+ *is_ipv6 = is_header_ipv6(data->header);
+ if (*is_ipv6) {
+ struct ovs_16aligned_ip6_hdr *ip6;
+
+ ip6 = ipv6_hdr(data->header);
+ ip6->ip6_nxt = next_proto;
+ *hlen += IPV6_HEADER_LEN;
+ return ip6 + 1;
+ } else {
+ struct ip_header *ip;
+
+ ip = ip_hdr(data->header);
+ ip->ip_proto = next_proto;
+ *hlen += IP_HEADER_LEN;
+ return ip + 1;
+ }
+}
+
extern uint16_t tnl_udp_port_min;
extern uint16_t tnl_udp_port_max;
--
2.5.5
More information about the dev
mailing list