naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0009-libnetlink-introduce-rta_nest-and-u8-u16-u64-helpers.patch

4aca6e
From ff021313a4175ec85193c25551698e58e85e86e0 Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Wed, 1 Feb 2017 14:20:11 +0100
4aca6e
Subject: [PATCH] libnetlink: introduce rta_nest and u8, u16, u64 helpers for
4aca6e
 nesting within rtattr
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1329730
4aca6e
Upstream Status: iproute2.git commit 303cc9cbeed6c
4aca6e
4aca6e
commit 303cc9cbeed6cfb9f08a4073f07cb466cc8098e8
4aca6e
Author: Roopa Prabhu <roopa@cumulusnetworks.com>
4aca6e
Date:   Thu Oct 15 13:13:38 2015 +0200
4aca6e
4aca6e
    libnetlink: introduce rta_nest and u8, u16, u64 helpers for nesting within rtattr
4aca6e
4aca6e
    This patch introduces two new api's rta_nest and rta_nest_end to
4aca6e
    nest attributes inside a rta attribute represented by 'struct rtattr'
4aca6e
    as required to construct a nexthop. Also adds rta_addattr* variants
4aca6e
    for u8, u16 and u64 as needed to support encapsulation.
4aca6e
4aca6e
    Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
4aca6e
    Signed-off-by: Thomas Graf <tgraf@suug.ch>
4aca6e
    Acked-by: Jiri Benc <jbenc@redhat.com>
4aca6e
---
4aca6e
 include/libnetlink.h | 10 ++++++++++
4aca6e
 lib/libnetlink.c     | 31 +++++++++++++++++++++++++++++++
4aca6e
 2 files changed, 41 insertions(+)
4aca6e
4aca6e
diff --git a/include/libnetlink.h b/include/libnetlink.h
4aca6e
index 40fa6ff..7ea3f4a 100644
4aca6e
--- a/include/libnetlink.h
4aca6e
+++ b/include/libnetlink.h
4aca6e
@@ -91,7 +91,10 @@ int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest);
4aca6e
 struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type,
4aca6e
 				   const void *data, int len);
4aca6e
 int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest);
4aca6e
+int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data);
4aca6e
+int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data);
4aca6e
 int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
4aca6e
+int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data);
4aca6e
 int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
4aca6e
 		  const void *data, int alen);
4aca6e
 
4aca6e
@@ -103,6 +106,13 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max,
4aca6e
 struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
4aca6e
 int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
4aca6e
 
4aca6e
+struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type);
4aca6e
+int rta_nest_end(struct rtattr *rta, struct rtattr *nest);
4aca6e
+
4aca6e
+#define RTA_TAIL(rta) \
4aca6e
+		((struct rtattr *) (((void *) (rta)) + \
4aca6e
+				    RTA_ALIGN((rta)->rta_len)))
4aca6e
+
4aca6e
 #define parse_rtattr_nested(tb, max, rta) \
4aca6e
 	(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
4aca6e
 
4aca6e
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
4aca6e
index 96bde59..9e653cc 100644
4aca6e
--- a/lib/libnetlink.c
4aca6e
+++ b/lib/libnetlink.c
4aca6e
@@ -723,6 +723,37 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
+int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data)
4aca6e
+{
4aca6e
+	return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u8));
4aca6e
+}
4aca6e
+
4aca6e
+int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data)
4aca6e
+{
4aca6e
+	return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u16));
4aca6e
+}
4aca6e
+
4aca6e
+int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data)
4aca6e
+{
4aca6e
+	return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u64));
4aca6e
+}
4aca6e
+
4aca6e
+struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type)
4aca6e
+{
4aca6e
+	struct rtattr *nest = RTA_TAIL(rta);
4aca6e
+
4aca6e
+	rta_addattr_l(rta, maxlen, type, NULL, 0);
4aca6e
+
4aca6e
+	return nest;
4aca6e
+}
4aca6e
+
4aca6e
+int rta_nest_end(struct rtattr *rta, struct rtattr *nest)
4aca6e
+{
4aca6e
+	nest->rta_len = (void *)RTA_TAIL(rta) - (void *)nest;
4aca6e
+
4aca6e
+	return rta->rta_len;
4aca6e
+}
4aca6e
+
4aca6e
 int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
4aca6e
 {
4aca6e
 	return parse_rtattr_flags(tb, max, rta, len, 0);
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e