Skip to contentSkip to conversation

Bare UDP L3 Encapsulation Module

PATCH Superseded Martin Varghese 2 participants 11 messages Feb 15, 2020 – Feb 24, 2020

Subsystems (4)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover Bare UDP L3 Encapsulation Module

From: Martin Varghese <[email protected]>

There are various L3 encapsulation standards using UDP being discussed to leverage the UDP based load balancing capability of different networks. MPLSoUDP (__ https://tools.ietf.org/html/rfc7510) is one among them.

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling support for tunnelling different L3 protocols like MPLS, IP, NSH etc. inside a UDP tunnel.

Special Handling
----------------
The bareudp device supports special handling for MPLS & IP as they can have multiple ethertypes.
MPLS procotcol can have ethertypes ETH_P_MPLS_UC (unicast) & ETH_P_MPLS_MC (multicast). IP protocol can have ethertypes ETH_P_IP (v4) & ETH_P_IPV6 (v6).
This special handling can be enabled only for ethertypes ETH_P_IP & ETH_P_MPLS_UC with a flag called multiproto mode.

Usage
------

1) Device creation & deletion

a) ip link add dev bareudp0 type bareudp dstport 6635 ethertype 0x8847.

This creates a bareudp tunnel device which tunnels L3 traffic with ethertype 0x8847 (MPLS traffic). The destination port of the UDP header will be set to 6635.The device will listen on UDP port 6635 to receive traffic.

b) ip link delete bareudp0

2) Device creation with multiple proto mode enabled

There are two ways to create a bareudp device for MPLS & IP with multiproto mode enabled.

a) ip link add dev bareudp0 type bareudp dstport 6635 ethertype 0x8847 multiproto

b) ip link add dev bareudp0 type bareudp dstport 6635 ethertype mpls

3) Device Usage

The bareudp device could be used along with OVS or flower filter in TC. The OVS or TC flower layer must set the tunnel information in SKB dst field before sending packet buffer to the bareudp device for transmission. On reception the bareudp device extracts and stores the tunnel information in SKB dst field before passing the packet buffer to the network stack.

Why not FOU ?
------------
FOU by design does l4 encapsulation.It maps udp port to ipproto (IP protocol number for l4 protocol). Bareudp acheives a generic l3 encapsulation.It maps udp port to l3 ethertype.

Martin Varghese (2):
net: UDP tunnel encapsulation module for tunnelling different
protocols like MPLS,IP,NSH etc.
net: Special handling for IP & MPLS.

 Documentation/networking/bareudp.rst |  53 +++
 Documentation/networking/index.rst   |   1 +
 drivers/net/Kconfig                  |  13 +
 drivers/net/Makefile                 |   1 +
 drivers/net/bareudp.c                | 803 +++++++++++++++++++++++++++++++++++
 include/net/bareudp.h                |  20 +
 include/net/ipv6.h                   |   6 +
 include/net/route.h                  |   6 +
 include/uapi/linux/if_link.h         |  12 +
 net/ipv4/route.c                     |  48 +++
 net/ipv6/ip6_output.c                |  70 +++
 11 files changed, 1033 insertions(+)
 create mode 100644 Documentation/networking/bareudp.rst
 create mode 100644 drivers/net/bareudp.c
 create mode 100644 include/net/bareudp.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v7 1/2 net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

From: Martin Varghese <[email protected]>

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling module for tunnelling different protocols like MPLS, IP,NSH etc inside a UDP tunnel.

---
Changes in v2:
- Fixed documentation errors.
- Converted documentation to rst format.
- Moved ip tunnel rt lookup code to a common location.
- Removed seperate v4 and v6 socket.
- Added call to skb_ensure_writable before updating ethernet header.
- Simplified bareudp_destroy_tunnels as deleting devices under a namespace is taken care be the default pernet exit code.
- Fixed bareudp_change_mtu.

Changes in v3:
- Re-sending the patch again.

Changes in v4:
- Converted bareudp device to l3 device.
- Removed redundant fields in bareudp device.
- Added device usage section in documentation

Changes in v5:
- Modified version 4 change log
- Added Select NET_UDP_TUNNEL in Bareudp config section
- Fixed bareudp index position in documentation index file.
- 1500 changed to ETH_DATA_LEN while setting MTU field.
- Replaced bareudp_change_mtu with core function dev_set_mtu.
- Removed udp header present redundant check in recv.

Changes in v6:
- Moved ip tunnel rt lookup code to ipv4/route.c & ipv6/ip6_route.c

Changes in v7:
- Re-Sending the patch

 Documentation/networking/bareudp.rst |  35 ++
 Documentation/networking/index.rst   |   1 +
 drivers/net/Kconfig                  |  13 +
 drivers/net/Makefile                 |   1 +
 drivers/net/bareudp.c                | 742 +++++++++++++++++++++++++++++++++++
 include/net/bareudp.h                |  19 +
 include/net/ipv6.h                   |   6 +
 include/net/route.h                  |   6 +
 include/uapi/linux/if_link.h         |  11 +
 net/ipv4/route.c                     |  48 +++
 net/ipv6/ip6_output.c                |  70 ++++
 11 files changed, 952 insertions(+)
 create mode 100644 Documentation/networking/bareudp.rst
 create mode 100644 drivers/net/bareudp.c
 create mode 100644 include/net/bareudp.h
Documentation/networking/bareudp.rst new file +35 -0
new file mode 100644
index 0000000..4087a1b
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+========================================
+Bare UDP Tunnelling Module Documentation
+========================================
+
+There are various L3 encapsulation standards using UDP being discussed to
+leverage the UDP based load balancing capability of different networks.
+MPLSoUDP (__ https://tools.ietf.org/html/rfc7510) is one among them.
+
+The Bareudp tunnel module provides a generic L3 encapsulation tunnelling
+support for tunnelling different L3 protocols like MPLS, IP, NSH etc. inside
+a UDP tunnel.
+
+Usage
+------
+
+1) Device creation & deletion
+
+    a) ip link add dev bareudp0 type bareudp dstport 6635 ethertype 0x8847.
+
+       This creates a bareudp tunnel device which tunnels L3 traffic with ethertype
+       0x8847 (MPLS traffic). The destination port of the UDP header will be set to
+       6635.The device will listen on UDP port 6635 to receive traffic.
+
+    b) ip link delete bareudp0
+
+2) Device Usage
+
+The bareudp device could be used along with OVS or flower filter in TC.
+The OVS or TC flower layer must set the tunnel information in SKB dst field before
+sending packet buffer to the bareudp device for transmission. On reception the
+bareudp device extracts and stores the tunnel information in SKB dst field before
+passing the packet buffer to the network stack.
+
Documentation/networking/index.rst +1 -0
index d07d985..3a83cfb 100644
@@ -8,6 +8,7 @@ Contents:
 
    netdev-FAQ
    af_xdp
+   bareudp
    batman-adv
    can
    can_ucan_protocol
drivers/net/Kconfig +13 -0
index 25a8f93..66e410e 100644
@@ -258,6 +258,19 @@ config GENEVE
 	  To compile this driver as a module, choose M here: the module
 	  will be called geneve.
 
+config BAREUDP
+       tristate "Bare UDP Encapsulation"
+       depends on INET
+       depends on IPV6 || !IPV6
+       select NET_UDP_TUNNEL
+       select GRO_CELLS
+       help
+          This adds a bare UDP tunnel module for tunnelling different
+          kinds of traffic like MPLS, IP, etc. inside a UDP tunnel.
+
+          To compile this driver as a module, choose M here: the module
+          will be called bareudp.
+
 config GTP
 	tristate "GPRS Tunneling Protocol datapath (GTP-U)"
 	depends on INET
drivers/net/Makefile +1 -0
index 71b88ff..6596724 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_VETH) += veth.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VXLAN) += vxlan.o
 obj-$(CONFIG_GENEVE) += geneve.o
+obj-$(CONFIG_BAREUDP) += bareudp.o
 obj-$(CONFIG_GTP) += gtp.o
 obj-$(CONFIG_NLMON) += nlmon.o
 obj-$(CONFIG_NET_VRF) += vrf.o
drivers/net/bareudp.c new file +742 -0

742 lines not on this page · raw message

include/net/bareudp.h new file +19 -0
new file mode 100644
index 0000000..513fae6
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __NET_BAREUDP_H
+#define __NET_BAREUDP_H
+
+#include <linux/types.h>
+#include <linux/skbuff.h>
+
+struct bareudp_conf {
+	__be16 ethertype;
+	__be16 port;
+	u16 sport_min;
+};
+
+struct net_device *bareudp_dev_create(struct net *net, const char *name,
+				      u8 name_assign_type,
+				      struct bareudp_conf *info);
+
+#endif
include/net/ipv6.h +6 -0
index cec1a54..1bf8065 100644
@@ -1027,6 +1027,12 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
 struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
 					 const struct in6_addr *final_dst,
 					 bool connected);
+struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb,
+					struct net_device *dev,
+					struct net *net, struct socket *sock,
+					struct in6_addr *saddr,
+					const struct ip_tunnel_info *info,
+					u8 protocol, bool use_cache);
 struct dst_entry *ip6_blackhole_route(struct net *net,
 				      struct dst_entry *orig_dst);
 
include/net/route.h +6 -0
index a9c60fc..81750ae 100644
@@ -128,6 +128,12 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
 				    const struct sock *sk);
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+				      struct net_device *dev,
+				      struct net *net, __be32 *saddr,
+				      const struct ip_tunnel_info *info,
+				      u8 protocol, bool use_cache);
+
 struct dst_entry *ipv4_blackhole_route(struct net *net,
 				       struct dst_entry *dst_orig);
 
include/uapi/linux/if_link.h +11 -0
index 024af2d..fb4b33a 100644
@@ -590,6 +590,17 @@ enum ifla_geneve_df {
 	GENEVE_DF_MAX = __GENEVE_DF_END - 1,
 };
 
+/* Bareudp section  */
+enum {
+	IFLA_BAREUDP_UNSPEC,
+	IFLA_BAREUDP_PORT,
+	IFLA_BAREUDP_ETHERTYPE,
+	IFLA_BAREUDP_SRCPORT_MIN,
+	__IFLA_BAREUDP_MAX
+};
+
+#define IFLA_BAREUDP_MAX (__IFLA_BAREUDP_MAX - 1)
+
 /* PPP section */
 enum {
 	IFLA_PPP_UNSPEC,
net/ipv4/route.c +48 -0

54 lines not on this page · raw message

net/ipv6/ip6_output.c +70 -0

82 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v7 2/2 net: Special handling for IP & MPLS.

In reply to Martin Varghese

From: Martin Varghese <[email protected]>

Special handling is needed in bareudp module for IP & MPLS as they support more than one ethertypes.

MPLS has 2 ethertypes. 0x8847 for MPLS unicast and 0x8848 for MPLS multicast. While decapsulating MPLS packet from UDP packet the tunnel destination IP address is checked to determine the ethertype. The ethertype of the packet will be set to 0x8848 if the tunnel destination IP address is a multicast IP address. The ethertype of the packet will be set to 0x8847 if the tunnel destination IP address is a unicast IP address.

IP has 2 ethertypes.0x0800 for IPV4 and 0x86dd for IPv6. The version field of the IP header tunnelled will be checked to determine the ethertype.

This special handling to tunnel additional ethertypes will be disabled by default and can be enabled using a flag called multiproto. This flag can be used only with ethertypes 0x8847 and 0x0800.

---
Changes in v2:
- Fixed documentation errors.
- Changed commit message.

Changes in v3:
- Re-sending the patch.

Changes in v4:
- Renamed extmode flag to multiproto
- Fixed typo in description.

Changes in v5:
- Mention about extmode is changed in multiproto in commit msg.
- Ack from Willem added.

Changes in v6:
- Sending Again.

Changes in v7:
- Re-sending the patch.

 Documentation/networking/bareudp.rst | 20 ++++++++++-
 drivers/net/bareudp.c                | 67 ++++++++++++++++++++++++++++++++++--
 include/net/bareudp.h                |  1 +
 include/uapi/linux/if_link.h         |  1 +
 4 files changed, 85 insertions(+), 4 deletions(-)
Documentation/networking/bareudp.rst +19 -1
index 4087a1b..9794dd8 100644
@@ -12,6 +12,15 @@ The Bareudp tunnel module provides a generic L3 encapsulation tunnelling
 support for tunnelling different L3 protocols like MPLS, IP, NSH etc. inside
 a UDP tunnel.
 
+Special Handling
+----------------
+The bareudp device supports special handling for MPLS & IP as they can have
+multiple ethertypes.
+MPLS procotcol can have ethertypes ETH_P_MPLS_UC  (unicast) & ETH_P_MPLS_MC (multicast).
+IP protocol can have ethertypes ETH_P_IP (v4) & ETH_P_IPV6 (v6).
+This special handling can be enabled only for ethertypes ETH_P_IP & ETH_P_MPLS_UC
+with a flag called multiproto mode.
+
 Usage
 ------
 
@@ -25,7 +34,16 @@ Usage
 
     b) ip link delete bareudp0
 
-2) Device Usage
+2) Device creation with multiple proto mode enabled
+
+There are two ways to create a bareudp device for MPLS & IP with multiproto mode
+enabled.
+
+    a) ip link add dev  bareudp0 type bareudp dstport 6635 ethertype 0x8847 multiproto
+
+    b) ip link add dev  bareudp0 type bareudp dstport 6635 ethertype mpls
+
+3) Device Usage
 
 The bareudp device could be used along with OVS or flower filter in TC.
 The OVS or TC flower layer must set the tunnel information in SKB dst field before
drivers/net/bareudp.c +64 -3

112 lines not on this page · raw message

include/net/bareudp.h +1 -0
index 513fae6..cb03f6f 100644
@@ -10,6 +10,7 @@ struct bareudp_conf {
 	__be16 ethertype;
 	__be16 port;
 	u16 sport_min;
+	bool multi_proto_mode;
 };
 
 struct net_device *bareudp_dev_create(struct net *net, const char *name,
include/uapi/linux/if_link.h +1 -0
index fb4b33a..61e0801 100644
@@ -596,6 +596,7 @@ enum {
 	IFLA_BAREUDP_PORT,
 	IFLA_BAREUDP_ETHERTYPE,
 	IFLA_BAREUDP_SRCPORT_MIN,
+	IFLA_BAREUDP_MULTIPROTO_MODE,
 	__IFLA_BAREUDP_MAX
 };
 
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Martin Varghese
Quoted 8 lines · Martin Varghese

From: Martin Varghese <[email protected]>

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling module for tunnelling different protocols like MPLS, IP,NSH etc inside a UDP tunnel.

A few small points

Quoted 2 lines
 net/ipv4/route.c                     |  48 +++
 net/ipv6/ip6_output.c                |  70 ++++

Both protocols have route.c and ip(6)_output.c files. For the sake of consistency, both should ideally be in route.c. Did you choose ip6_output.c for a reason?

There are also a couple of reverse christmas tree violations.

Quoted 19 lines
net/ipv4/route.c +19 -0
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct rtable *rt = NULL;
+       struct flowi4 fl4;
+       __u8 tos;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.flowi4_mark = skb->mark;
+       fl4.flowi4_proto = protocol;
+       fl4.daddr = info->key.u.ipv4.dst;
+       fl4.saddr = info->key.u.ipv4.src;
+

net/ipv4/route.c struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, · line 2805

Quoted 10 lines
net/ipv4/route.c +10 -0
+       tos = info->key.tos;
+       fl4.flowi4_tos = RT_TOS(tos);
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
+               rt = dst_cache_get_ip4(dst_cache, saddr);
+               if (rt)
+                       return rt;
+       }
+#endif

This is the same in geneve, but no need to initialize fl4 on a cache hit. Then can also be restructured to only have a single #ifdef block.

#7 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Martin Varghese
Quoted 20 lines · Martin Varghese

From: Martin Varghese <[email protected]>

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling module for tunnelling different protocols like MPLS, IP,NSH etc inside a UDP tunnel.

drivers/net/bareudp.c new file +11 -0
+struct net_device *bareudp_dev_create(struct net *net, const char *name,
+                                     u8 name_assign_type,
+                                     struct bareudp_conf *conf)
+{
+       struct nlattr *tb[IFLA_MAX + 1];
+       struct net_device *dev;
+       LIST_HEAD(list_kill);
+       int err;
+
+       memset(tb, 0, sizeof(tb));
+       dev = rtnl_create_link(net, name, name_assign_type,

drivers/net/bareudp.c line 659

Quoted 10 lines
drivers/net/bareudp.c new file +10 -0
+                              &bareudp_link_ops, tb, NULL);
+       if (IS_ERR(dev))
+               return dev;
+
+       err = bareudp_configure(net, dev, conf);
+       if (err) {
+               free_netdev(dev);
+               return ERR_PTR(err);
+       }
+       err = dev_set_mtu(dev, IP_MAX_MTU);

does this not exceed dev->max_mtu?

Quoted 24 lines
include/net/ipv6.h +6 -0
index cec1a54..1bf8065 100644
@@ -1027,6 +1027,12 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
 struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
                                         const struct in6_addr *final_dst,
                                         bool connected);
+struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb,
+                                       struct net_device *dev,
+                                       struct net *net, struct socket *sock,
+                                       struct in6_addr *saddr,
+                                       const struct ip_tunnel_info *info,
+                                       u8 protocol, bool use_cache);
 struct dst_entry *ip6_blackhole_route(struct net *net,
                                      struct dst_entry *orig_dst);
 
include/net/route.h +0 -0
index a9c60fc..81750ae 100644
@@ -128,6 +128,12 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,

include/net/route.h static inline struct rtable *__ip_route_output_key(struct net *net, · line 139

Quoted 10 lines
include/net/route.h +6 -0
                                    const struct sock *sk);
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache);
+
 struct dst_entry *ipv4_blackhole_route(struct net *net,
                                       struct dst_entry *dst_orig);
 

Ah, I now see where the difference between net/ipv4/route.c and net/ipv6/ip6_output.c come from. It follows from existing locations of
ip6_sk_dst_lookup_flow and ip_route_output_flow.

Looking for the ipv6 analog of ip_route_output_flow, I see that, e.g., ipvlan uses ip6_route_output from net/ipv6/route.c without a NULL sk. But ping calls ip6_sk_dst_lookup_flow.

It might be a better fit behind ip6_route_output_flags, but it's probably moot, really.

#3 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Willem de Bruijn
Quoted 13 lines · Willem de Bruijn
Quoted 8 lines · Martin Varghese

From: Martin Varghese <[email protected]>

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling module for tunnelling different protocols like MPLS, IP,NSH etc inside a UDP tunnel.

A few small points

Quoted 9 lines
Quoted 2 lines
 net/ipv4/route.c                     |  48 +++
 net/ipv6/ip6_output.c                |  70 ++++

Both protocols have route.c and ip(6)_output.c files. For the sake of consistency, both should ideally be in route.c. Did you choose ip6_output.c for a reason?

There are also a couple of reverse christmas tree violations.

In Bareudp.c correct?
Wondering if there is any flag in checkpatch to catch them?

Quoted 24 lines
Quoted 24 lines
net/ipv4/route.c +24 -0
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct rtable *rt = NULL;
+       struct flowi4 fl4;
+       __u8 tos;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.flowi4_mark = skb->mark;
+       fl4.flowi4_proto = protocol;
+       fl4.daddr = info->key.u.ipv4.dst;
+       fl4.saddr = info->key.u.ipv4.src;
+
+       tos = info->key.tos;
+       fl4.flowi4_tos = RT_TOS(tos);
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
Quoted 8 lines

net/ipv4/route.c struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, · line 2805

Quoted 5 lines
net/ipv4/route.c +5 -0
+               rt = dst_cache_get_ip4(dst_cache, saddr);
+               if (rt)
+                       return rt;
+       }
+#endif

This is the same in geneve, but no need to initialize fl4 on a cache hit. Then can also be restructured to only have a single #ifdef block.

Yes , We need not initialize fl4 when cache is used.
But i didnt get your point on restructuing to have a single #ifdef block Could you please give more details

#8 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Willem de Bruijn
Quoted 26 lines · Willem de Bruijn
Quoted 24 lines · Martin Varghese

From: Martin Varghese <[email protected]>

The Bareudp tunnel module provides a generic L3 encapsulation tunnelling module for tunnelling different protocols like MPLS, IP,NSH etc inside a UDP tunnel.

drivers/net/bareudp.c new file +15 -0
+struct net_device *bareudp_dev_create(struct net *net, const char *name,
+                                     u8 name_assign_type,
+                                     struct bareudp_conf *conf)
+{
+       struct nlattr *tb[IFLA_MAX + 1];
+       struct net_device *dev;
+       LIST_HEAD(list_kill);
+       int err;
+
+       memset(tb, 0, sizeof(tb));
+       dev = rtnl_create_link(net, name, name_assign_type,
+                              &bareudp_link_ops, tb, NULL);
+       if (IS_ERR(dev))
+               return dev;
+
Quoted 9 lines

drivers/net/bareudp.c line 659

Quoted 6 lines
drivers/net/bareudp.c new file +6 -0
+       err = bareudp_configure(net, dev, conf);
+       if (err) {
+               free_netdev(dev);
+               return ERR_PTR(err);
+       }
+       err = dev_set_mtu(dev, IP_MAX_MTU);

does this not exceed dev->max_mtu?

Noted.Must consider BAREUDP Overhead.

Quoted 39 lines
Quoted 24 lines
include/net/ipv6.h +6 -0
index cec1a54..1bf8065 100644
@@ -1027,6 +1027,12 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
 struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
                                         const struct in6_addr *final_dst,
                                         bool connected);
+struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb,
+                                       struct net_device *dev,
+                                       struct net *net, struct socket *sock,
+                                       struct in6_addr *saddr,
+                                       const struct ip_tunnel_info *info,
+                                       u8 protocol, bool use_cache);
 struct dst_entry *ip6_blackhole_route(struct net *net,
                                      struct dst_entry *orig_dst);
 
include/net/route.h +0 -0
index a9c60fc..81750ae 100644
@@ -128,6 +128,12 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,

include/net/route.h static inline struct rtable *__ip_route_output_key(struct net *net, · line 139

Quoted 10 lines
include/net/route.h +6 -0
                                    const struct sock *sk);
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache);
+
 struct dst_entry *ipv4_blackhole_route(struct net *net,
                                       struct dst_entry *dst_orig);
 

Ah, I now see where the difference between net/ipv4/route.c and net/ipv6/ip6_output.c come from. It follows from existing locations of
ip6_sk_dst_lookup_flow and ip_route_output_flow.

Quoted 6 lines

Looking for the ipv6 analog of ip_route_output_flow, I see that, e.g., ipvlan uses ip6_route_output from net/ipv6/route.c without a NULL sk. But ping calls ip6_sk_dst_lookup_flow.

It might be a better fit behind ip6_route_output_flags, but it's probably moot, really.

Actually i considered both the files but i felt this function should naturally sit with ip6_sk_dst_lookup_flow. If you dont have strong objection i would like to keep the function in ip6_output.c

#4 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Martin Varghese
Quoted 3 lines
Quoted 2 lines

There are also a couple of reverse christmas tree violations.

In Bareudp.c correct?

Right. Like bareudp_udp_encap_recv.

Quoted 1 line

Wondering if there is any flag in checkpatch to catch them?

It has come up, but I don't believe anything is merged.

Quoted 32 lines
Quoted 24 lines
Quoted 24 lines
net/ipv4/route.c +24 -0
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct rtable *rt = NULL;
+       struct flowi4 fl4;
+       __u8 tos;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.flowi4_mark = skb->mark;
+       fl4.flowi4_proto = protocol;
+       fl4.daddr = info->key.u.ipv4.dst;
+       fl4.saddr = info->key.u.ipv4.src;
+
+       tos = info->key.tos;
+       fl4.flowi4_tos = RT_TOS(tos);
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
Quoted 8 lines

net/ipv4/route.c struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, · line 2805

Quoted 5 lines
net/ipv4/route.c +5 -0
+               rt = dst_cache_get_ip4(dst_cache, saddr);
+               if (rt)
+                       return rt;
+       }
+#endif

This is the same in geneve, but no need to initialize fl4 on a cache hit. Then can also be restructured to only have a single #ifdef block.

Quoted 3 lines

Yes , We need not initialize fl4 when cache is used.
But i didnt get your point on restructuing to have a single #ifdef block Could you please give more details

Actually, I was mistaken, missing the third #ifdef block that calls dst_cache_set_ip[46]. But the type of info->dst_cache is struct dst_cache, so I don't think the explicit cast or additional pointer variable (and with that the first #ifdef) is needed. But it's clearly not terribly important.

#9 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Martin Varghese
Quoted 43 lines
Quoted 43 lines
Quoted 24 lines
include/net/ipv6.h +6 -0
index cec1a54..1bf8065 100644
@@ -1027,6 +1027,12 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
 struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
                                         const struct in6_addr *final_dst,
                                         bool connected);
+struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb,
+                                       struct net_device *dev,
+                                       struct net *net, struct socket *sock,
+                                       struct in6_addr *saddr,
+                                       const struct ip_tunnel_info *info,
+                                       u8 protocol, bool use_cache);
 struct dst_entry *ip6_blackhole_route(struct net *net,
                                      struct dst_entry *orig_dst);
 
include/net/route.h +0 -0
index a9c60fc..81750ae 100644
@@ -128,6 +128,12 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,

include/net/route.h static inline struct rtable *__ip_route_output_key(struct net *net, · line 139

Quoted 10 lines
include/net/route.h +6 -0
                                    const struct sock *sk);
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache);
+
 struct dst_entry *ipv4_blackhole_route(struct net *net,
                                       struct dst_entry *dst_orig);
 

Ah, I now see where the difference between net/ipv4/route.c and net/ipv6/ip6_output.c come from. It follows from existing locations of
ip6_sk_dst_lookup_flow and ip_route_output_flow.

Looking for the ipv6 analog of ip_route_output_flow, I see that, e.g., ipvlan uses ip6_route_output from net/ipv6/route.c without a NULL sk. But ping calls ip6_sk_dst_lookup_flow.

Quoted 7 lines
Quoted 2 lines

It might be a better fit behind ip6_route_output_flags, but it's probably moot, really.

Actually i considered both the files but i felt this function should naturally sit with ip6_sk_dst_lookup_flow. If you dont have strong objection i would like to keep the function in ip6_output.c

Yes, sounds good, thanks. The difference stood out to me in an initial git show --stat, but on closer reading both choices can be argued for.

#5 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

In reply to Willem de Bruijn
Quoted 46 lines · Willem de Bruijn
Quoted 3 lines
Quoted 2 lines

There are also a couple of reverse christmas tree violations.

In Bareudp.c correct?

Right. Like bareudp_udp_encap_recv.

Quoted 1 line

Wondering if there is any flag in checkpatch to catch them?

It has come up, but I don't believe anything is merged.

Quoted 32 lines
Quoted 24 lines
Quoted 24 lines
net/ipv4/route.c +24 -0
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct rtable *rt = NULL;
+       struct flowi4 fl4;
+       __u8 tos;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.flowi4_mark = skb->mark;
+       fl4.flowi4_proto = protocol;
+       fl4.daddr = info->key.u.ipv4.dst;
+       fl4.saddr = info->key.u.ipv4.src;
+
+       tos = info->key.tos;
+       fl4.flowi4_tos = RT_TOS(tos);
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
Quoted 8 lines

net/ipv4/route.c struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, · line 2805

Quoted 5 lines
net/ipv4/route.c +5 -0
+               rt = dst_cache_get_ip4(dst_cache, saddr);
+               if (rt)
+                       return rt;
+       }
+#endif

This is the same in geneve, but no need to initialize fl4 on a cache hit. Then can also be restructured to only have a single #ifdef block.

Quoted 3 lines

Yes , We need not initialize fl4 when cache is used.
But i didnt get your point on restructuing to have a single #ifdef block Could you please give more details

Quoted 5 lines

Actually, I was mistaken, missing the third #ifdef block that calls dst_cache_set_ip[46]. But the type of info->dst_cache is struct dst_cache, so I don't think the explicit cast or additional pointer variable (and with that the first #ifdef) is needed. But it's clearly not terribly important.

I tried to remove the additional pointer variable and the explicit cast.But Compiler warns as the info is a const variable (same for geneve)

So shall we keep as it is ?

#6 lore raw

Re: [PATCH net-next v7 1/2] net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS,IP,NSH etc.

Quoted 53 lines · Martin Varghese
Quoted 46 lines · Willem de Bruijn
Quoted 3 lines
Quoted 2 lines

There are also a couple of reverse christmas tree violations.

In Bareudp.c correct?

Right. Like bareudp_udp_encap_recv.

Quoted 1 line

Wondering if there is any flag in checkpatch to catch them?

It has come up, but I don't believe anything is merged.

Quoted 32 lines
Quoted 24 lines
Quoted 24 lines
net/ipv4/route.c +24 -0
+struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
+                                     struct net_device *dev,
+                                     struct net *net, __be32 *saddr,
+                                     const struct ip_tunnel_info *info,
+                                     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct rtable *rt = NULL;
+       struct flowi4 fl4;
+       __u8 tos;
+
+       memset(&fl4, 0, sizeof(fl4));
+       fl4.flowi4_mark = skb->mark;
+       fl4.flowi4_proto = protocol;
+       fl4.daddr = info->key.u.ipv4.dst;
+       fl4.saddr = info->key.u.ipv4.src;
+
+       tos = info->key.tos;
+       fl4.flowi4_tos = RT_TOS(tos);
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
Quoted 8 lines

net/ipv4/route.c struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, · line 2805

Quoted 5 lines
net/ipv4/route.c +5 -0
+               rt = dst_cache_get_ip4(dst_cache, saddr);
+               if (rt)
+                       return rt;
+       }
+#endif

This is the same in geneve, but no need to initialize fl4 on a cache hit. Then can also be restructured to only have a single #ifdef block.

Quoted 3 lines

Yes , We need not initialize fl4 when cache is used.
But i didnt get your point on restructuing to have a single #ifdef block Could you please give more details

Quoted 5 lines

Actually, I was mistaken, missing the third #ifdef block that calls dst_cache_set_ip[46]. But the type of info->dst_cache is struct dst_cache, so I don't think the explicit cast or additional pointer variable (and with that the first #ifdef) is needed. But it's clearly not terribly important.

Quoted 4 lines

I tried to remove the additional pointer variable and the explicit cast.But Compiler warns as the info is a const variable (same for geneve)

So shall we keep as it is ?

Thanks for giving it a try. Yes, that's fine then.