[systemd-devel] [PATCH 1/1] sd-rtnl: add support for tunnel attributes

Susant Sahani susant at redhat.com
Sun Mar 23 08:14:09 PDT 2014


Added support for tunneling netlink attrributes (ipip, gre, sit).
These works with kernel module ipip, gre and sit . The test cases are
commented out because they requirs super user privileges to run and
respective kernel modules as well.
---
 src/libsystemd/sd-rtnl/rtnl-message.c | 37 +++++++++++++++++---
 src/libsystemd/sd-rtnl/test-rtnl.c    | 64 +++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 4 deletions(-)

diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index e243c7b..6c7bda8 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -24,6 +24,9 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <linux/veth.h>
+#include <linux/if.h>
+#include <linux/ip.h>
+#include <linux/if_tunnel.h>
 
 #include "util.h"
 #include "refcnt.h"
@@ -458,6 +461,12 @@ int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t d
                                 case IFLA_CARRIER:
                                 case IFLA_OPERSTATE:
                                 case IFLA_LINKMODE:
+                                case IFLA_IPTUN_TTL:
+                                case IFLA_IPTUN_TOS:
+                                case IFLA_IPTUN_PROTO:
+                                case IFLA_IPTUN_PMTUDISC:
+                                case IFLA_IPTUN_ENCAP_LIMIT:
+                                case IFLA_GRE_TTL:
                                 break;
                         default:
                                 return -ENOTSUP;
@@ -495,12 +504,22 @@ int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t
                 case RTM_DELLINK:
                         if (m->n_containers == 2 &&
                             GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO &&
-                            GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA &&
-                            type == IFLA_VLAN_ID)
-                                break;
-                        else
+                            GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA) {
+                                switch (type) {
+                                       case IFLA_VLAN_ID:
+                                       case IFLA_IPTUN_FLAGS:
+                                       case IFLA_GRE_IFLAGS:
+                                       case IFLA_GRE_OFLAGS:
+                                       case IFLA_IPTUN_6RD_PREFIXLEN:
+                                       case IFLA_IPTUN_6RD_RELAY_PREFIXLEN:
+                                               break;
+                                       default:
+                                            return -ENOTSUP;
+                                }
+                        } else
                                 return -ENOTSUP;
 
+                        break;
                 default:
                         return -ENOTSUP;
         }
@@ -541,7 +560,12 @@ int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t
                                 case IFLA_PROMISCUITY:
                                 case IFLA_NUM_TX_QUEUES:
                                 case IFLA_NUM_RX_QUEUES:
+                                case IFLA_IPTUN_LOCAL:
+                                case IFLA_IPTUN_REMOTE:
                                 case IFLA_MACVLAN_MODE:
+                                case IFLA_IPTUN_FLAGS:
+                                case IFLA_IPTUN_FLOWINFO:
+                                case IFLA_GRE_FLOWINFO:
                                         break;
                                 default:
                                         return -ENOTSUP;
@@ -596,6 +620,8 @@ int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, cons
                                 case IFA_LOCAL:
                                 case IFA_BROADCAST:
                                 case IFA_ANYCAST:
+                                case IFLA_GRE_LOCAL:
+                                case IFLA_GRE_REMOTE:
                                         ifa = NLMSG_DATA(m->hdr);
 
                                         if (ifa->ifa_family != AF_INET)
@@ -658,6 +684,9 @@ int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, con
                                 case IFA_LOCAL:
                                 case IFA_BROADCAST:
                                 case IFA_ANYCAST:
+                                case IFLA_GRE_LOCAL:
+                                case IFLA_GRE_REMOTE:
+                                case IFLA_IPTUN_6RD_PREFIX:
                                         ifa = NLMSG_DATA(m->hdr);
 
                                         if (ifa->ifa_family != AF_INET6)
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 6ecd660..a4edf1d 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -20,6 +20,10 @@
 ***/
 
 #include <netinet/ether.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <linux/ip.h>
+#include <linux/if_tunnel.h>
 
 #include "util.h"
 #include "macro.h"
@@ -147,6 +151,64 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) {
         assert_se((r = sd_rtnl_message_unref(r)) == NULL);
 }
 
+#if 0
+static void test_tunnel_configure(sd_rtnl *rtnl) {
+        sd_rtnl_message *m;
+        struct in_addr local, remote;
+
+        /* IPIP tunnel */
+        assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINK, 0) >= 0);
+        assert_se(m);
+
+        assert_se(sd_rtnl_message_append_string(m, IFLA_IFNAME, "eth0") >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_MTU, 1234)>= 0);
+
+        assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
+        assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "ipip") >= 0);
+
+        assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
+
+        inet_pton(AF_INET, "192.168.21.1", &local.s_addr);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
+
+        inet_pton(AF_INET, "192.168.21.2", &remote.s_addr);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
+
+        assert_se(sd_rtnl_message_close_container(m) >= 0);
+        assert_se(sd_rtnl_message_close_container(m) >= 0);
+
+        assert_se(sd_rtnl_call(rtnl, m, -1, 0) == 1);
+
+        assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+
+        /* sit */
+        assert_se(sd_rtnl_message_new_link(rtnl, &n, RTM_NEWLINK, 0) >= 0);
+        assert_se(n);
+
+        assert_se(sd_rtnl_message_append_string(n, IFLA_IFNAME, "eth1") >= 0);
+        assert_se(sd_rtnl_message_append_u32(n, IFLA_MTU, 1234)>= 0);
+
+        assert_se(sd_rtnl_message_open_container(n, IFLA_LINKINFO) >= 0);
+        assert_se(sd_rtnl_message_append_string(n, IFLA_INFO_KIND, "sit") >= 0);
+
+        assert_se(sd_rtnl_message_open_container(n, IFLA_INFO_DATA) >= 0);
+
+        assert_se(sd_rtnl_message_append_u8(n, IFLA_IPTUN_PROTO, IPPROTO_IPIP) >= 0);
+
+        inet_pton(AF_INET, "192.168.21.3", &local.s_addr);
+        assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_LOCAL, local.s_addr) >= 0);
+
+        inet_pton(AF_INET, "192.168.21.4", &remote.s_addr);
+        assert_se(sd_rtnl_message_append_u32(n, IFLA_IPTUN_REMOTE, remote.s_addr) >= 0);
+
+        assert_se(sd_rtnl_message_close_container(n) >= 0);
+        assert_se(sd_rtnl_message_close_container(n) >= 0);
+
+        assert_se(sd_rtnl_call(rtnl, n, -1, 0) == 1);
+
+        assert_se((m = sd_rtnl_message_unref(n)) == NULL);
+}
+#endif
 
 static void test_address_get(sd_rtnl *rtnl, int ifindex) {
         sd_rtnl_message *m;
@@ -468,6 +530,8 @@ int main(void) {
         test_link_get(rtnl, if_loopback);
         test_address_get(rtnl, if_loopback);
 
+        /* test_tunnel_configure(rtnl); */
+
         assert_se(sd_rtnl_flush(rtnl) >= 0);
         assert_se((m = sd_rtnl_message_unref(m)) == NULL);
         assert_se((r = sd_rtnl_message_unref(r)) == NULL);
-- 
1.8.5.3



More information about the systemd-devel mailing list