Skip to contentSkip to conversation

fou: Support binding FoU socket

PATCH Superseded Kristian Evensen 3 participants 5 messages Mar 20, 2019 – Mar 26, 2019 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fou: Support binding FoU socket

An FoU socket is currently bound to the wildcard-address. While this works fine, there are several use-cases where the use of the wildcard-address is not desirable. For example, I use FoU on some multi-homed servers and would like to use FoU on only one of the interfaces.

This commit adds support for binding FoU sockets to a given source address/interface, as well as connecting the socket to a given destination address/port. udp_tunnel already provides the required infrastructure, so most of the code added is for exposing and setting the different attributes (local address, peer address, etc.).

The lookups performed when we add, delete or get an FoU-socket has also been updated to compare all the attributes a user can set. Since the comparison now involves several elements, I have added a separate comparison-function instead of open-coding.

I have been running this code for a while on some servers I am responsible for, and I have not found any regressions. If none of the new attributes are provided, then an FoU-socket is configured as before. If any of the new attributes are provided, the FoU-socket is configured as expected.

---
 include/uapi/linux/fou.h |   6 ++
 net/ipv4/fou.c           | 121 +++++++++++++++++++++++++++++++++------
 2 files changed, 111 insertions(+), 16 deletions(-)
include/uapi/linux/fou.h +6 -0
index f2ea833a2812..87c2c9f08803 100644
@@ -16,6 +16,12 @@ enum {
 	FOU_ATTR_IPPROTO,			/* u8 */
 	FOU_ATTR_TYPE,				/* u8 */
 	FOU_ATTR_REMCSUM_NOPARTIAL,		/* flag */
+	FOU_ATTR_LOCAL_V4,			/* u32 */
+	FOU_ATTR_LOCAL_V6,			/* in6_addr */
+	FOU_ATTR_PEER_V4,			/* u32 */
+	FOU_ATTR_PEER_V6,			/* in6_addr */
+	FOU_ATTR_PEER_PORT,			/* u16 */
+	FOU_ATTR_IFINDEX,			/* s32 */
 
 	__FOU_ATTR_MAX,
 };
net/ipv4/fou.c +105 -16

193 lines not on this page · raw message

Signature · 1 line
2.19.1
maintainer
#1 lore raw

From: Kristian Evensen <[email protected]>
Date: Wed, 20 Mar 2019 09:25:28 +0100

Quoted 4 lines

The lookups performed when we add, delete or get an FoU-socket has also been updated to compare all the attributes a user can set. Since the comparison now involves several elements, I have added a separate comparison-function instead of open-coding.

This seems to allow adding both a wildcarded and a non-wildcarded fou socket, which otherwise has overlapping match scenerios.

I don't think you want to allow that unless you can determine that you aren't creating a situation where multiple fou sockets could match the same tunneled packet.

#2 lore raw

Hi,

Quoted 6 lines · David Miller

This seems to allow adding both a wildcarded and a non-wildcarded fou socket, which otherwise has overlapping match scenerios.

I don't think you want to allow that unless you can determine that you aren't creating a situation where multiple fou sockets could match the same tunneled packet.

(Apologies to David for multiple copies of this reply. I thought I was safe from HTML-encoded emails when using Gmail through the browser. Turns out not to be true for mobile ...)

Thanks for your comments and apoligies for my late reply, Gmail flagged you message as spam for some reason.

I tried to test and make sure that we would not get any false positives when mixing non-wildcarded/wildcarded sockets. In my tests, I first created a wildcard socket bound to port 9999. I then tried to add a second, non-wildcarded socket bound to the same port. I also tried to fetch and delete the socket, including souce address, peer address or interface index in the netlink request. Both the create, fetch and delete request failed. Deleting/fetching the socket was only successful when my netlink request attributes matched those used to create the socket.

I then did the same tests, but with a socket bound to a local ip address, a socket bound to a local address + interface, and a bound socket that was also «connected» to a peer. Add only worked when no socket with the matching source address/interface (or wildcard) existed, while fetch/delete was only succesful when all attributes matched.

Perhaps there is something I am misunderstanding, or a case I am not aware of?

Thanks again for your comments!

BR,
Kristian

A message that is not in the archive (sent off-list or not yet received): CAKfDRXgFEqFk39L=x07+NyYZRqTn0sAmKbmZeqNCYWNObbsy5Q@mail.gmail.com

maintainer
#4 lore raw

From: Kristian Evensen <[email protected]>
Date: Sun, 24 Mar 2019 10:24:55 +0100

Quoted 2 lines

Perhaps there is something I am misunderstanding, or a case I am not aware of?

Ok if all of your tests pass then my concerns are addressed.

Please deal with the kbuild robot reported build failures and resubmit, thanks.

#5 lore raw
In reply to Kristian Evensen
Thank you for the patch! Yet something to improve:

Hi Kristian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url: https://github.com/0day-ci/linux/commits/Kristian-Evensen/fou-Support-binding-FoU-socket/20190321-232759
config: x86_64-kexec (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

In file included from include/net/inet_sock.h:26:0,

                    from include/linux/udp.h:20,
                    from net/ipv4/fou.c:7:
   net/ipv4/fou.c: In function 'fou_cfg_cmp':
>> include/net/sock.h:361:37: error: 'struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'?
    #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
                                        ^
>> net/ipv4/fou.c:515:24: note: in expansion of macro 'sk_v6_rcv_saddr'
       !ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) &&
                           ^~~~~~~~~~~~~~~
>> net/ipv4/fou.c:515:51: error: 'struct udp_port_cfg' has no member named 'local_ip6'; did you mean 'local_ip'?
       !ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) &&
                                                      ^~~~~~~~~
                                                      local_ip
   In file included from include/net/inet_sock.h:26:0,
                    from include/linux/udp.h:20,
                    from net/ipv4/fou.c:7:
>> include/net/sock.h:360:34: error: 'struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'?
    #define sk_v6_daddr  __sk_common.skc_v6_daddr
                                     ^
>> net/ipv4/fou.c:516:24: note: in expansion of macro 'sk_v6_daddr'
       !ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6)));
                           ^~~~~~~~~~~
>> net/ipv4/fou.c:516:47: error: 'struct udp_port_cfg' has no member named 'peer_ip6'; did you mean 'peer_ip'?
       !ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6)));
                                                  ^~~~~~~~
                                                  peer_ip
   net/ipv4/fou.c: In function 'parse_nl_config':
   net/ipv4/fou.c:713:20: error: 'struct udp_port_cfg' has no member named 'local_ip6'; did you mean 'local_ip'?
       cfg->udp_config.local_ip6 = nla_get_in6_addr(attr);
                       ^~~~~~~~~
                       local_ip
   net/ipv4/fou.c:719:20: error: 'struct udp_port_cfg' has no member named 'peer_ip6'; did you mean 'peer_ip'?
       cfg->udp_config.peer_ip6 = nla_get_in6_addr(attr);
                       ^~~~~~~~
                       peer_ip
   In file included from include/net/inet_sock.h:26:0,
                    from include/linux/udp.h:20,
                    from net/ipv4/fou.c:7:
   net/ipv4/fou.c: In function 'fou_fill_info':
>> include/net/sock.h:361:37: error: 'struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'?
    #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
                                        ^
   net/ipv4/fou.c:796:15: note: in expansion of macro 'sk_v6_rcv_saddr'
             &sk->sk_v6_rcv_saddr))
                  ^~~~~~~~~~~~~~~
>> include/net/sock.h:360:34: error: 'struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'?
    #define sk_v6_daddr  __sk_common.skc_v6_daddr
                                     ^
   net/ipv4/fou.c:799:52: note: in expansion of macro 'sk_v6_daddr'
      if (nla_put_in6_addr(msg, FOU_ATTR_PEER_V6, &sk->sk_v6_daddr))
                                                       ^~~~~~~~~~~
   net/ipv4/fou.c: In function 'fou_cfg_cmp':
   net/ipv4/fou.c:517:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
--
   In file included from include/net/inet_sock.h:26:0,
                    from include/linux/udp.h:20,
                    from net//ipv4/fou.c:7:
   net//ipv4/fou.c: In function 'fou_cfg_cmp':
>> include/net/sock.h:361:37: error: 'struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'?
    #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
                                        ^
   net//ipv4/fou.c:515:24: note: in expansion of macro 'sk_v6_rcv_saddr'
       !ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) &&
                           ^~~~~~~~~~~~~~~
   net//ipv4/fou.c:515:51: error: 'struct udp_port_cfg' has no member named 'local_ip6'; did you mean 'local_ip'?
       !ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) &&
                                                      ^~~~~~~~~
                                                      local_ip
   In file included from include/net/inet_sock.h:26:0,
                    from include/linux/udp.h:20,
                    from net//ipv4/fou.c:7:
>> include/net/sock.h:360:34: error: 'struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'?
    #define sk_v6_daddr  __sk_common.skc_v6_daddr
                                     ^
   net//ipv4/fou.c:516:24: note: in expansion of macro 'sk_v6_daddr'
       !ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6)));
                           ^~~~~~~~~~~
   net//ipv4/fou.c:516:47: error: 'struct udp_port_cfg' has no member named 'peer_ip6'; did you mean 'peer_ip'?
       !ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6)));
                                                  ^~~~~~~~
                                                  peer_ip
   net//ipv4/fou.c: In function 'parse_nl_config':
   net//ipv4/fou.c:713:20: error: 'struct udp_port_cfg' has no member named 'local_ip6'; did you mean 'local_ip'?
       cfg->udp_config.local_ip6 = nla_get_in6_addr(attr);
                       ^~~~~~~~~
                       local_ip
   net//ipv4/fou.c:719:20: error: 'struct udp_port_cfg' has no member named 'peer_ip6'; did you mean 'peer_ip'?
       cfg->udp_config.peer_ip6 = nla_get_in6_addr(attr);
                       ^~~~~~~~
                       peer_ip
   In file included from include/net/inet_sock.h:26:0,
                    from include/linux/udp.h:20,
                    from net//ipv4/fou.c:7:
   net//ipv4/fou.c: In function 'fou_fill_info':
>> include/net/sock.h:361:37: error: 'struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'?
    #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
                                        ^
   net//ipv4/fou.c:796:15: note: in expansion of macro 'sk_v6_rcv_saddr'
             &sk->sk_v6_rcv_saddr))
                  ^~~~~~~~~~~~~~~
>> include/net/sock.h:360:34: error: 'struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'?
    #define sk_v6_daddr  __sk_common.skc_v6_daddr
                                     ^
   net//ipv4/fou.c:799:52: note: in expansion of macro 'sk_v6_daddr'
      if (nla_put_in6_addr(msg, FOU_ATTR_PEER_V6, &sk->sk_v6_daddr))
                                                       ^~~~~~~~~~~
   net//ipv4/fou.c: In function 'fou_cfg_cmp':
   net//ipv4/fou.c:517:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^

vim +515 net/ipv4/fou.c

501
502 static bool fou_cfg_cmp(struct fou *fou, struct fou_cfg *cfg)
503 {
504 struct sock *sk = fou->sock->sk;
505 struct udp_port_cfg *udp_cfg = &cfg->udp_config;
506
507 return fou->family == udp_cfg->family &&

   508		       fou->port == udp_cfg->local_udp_port &&
   509		       sk->sk_dport == udp_cfg->peer_udp_port &&
   510		       sk->sk_bound_dev_if == udp_cfg->bind_ifindex &&
   511		       ((fou->family == AF_INET &&
   512			 sk->sk_rcv_saddr == udp_cfg->local_ip.s_addr &&
   513			 sk->sk_daddr == udp_cfg->peer_ip.s_addr) ||
   514			(fou->family == AF_INET6 &&
 > 515			 !ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) &&
 > 516			 !ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6)));

517 }
518

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation