Skip to contentSkip to conversation

ip: Use the `struct fib_rule_hdr` for rules

PATCH Superseded Donald Sharp 2 participants 2 messages Feb 21, 2018

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 ip: Use the `struct fib_rule_hdr` for rules

The iprule.c code was using struct rtmsg as the data type to pass into the kernel for the netlink message. While 'struct rtmsg' and struct fib_rule_hdr are the same size and mostly the same, we should use the correct data structure. This commit translates the data structures to have iprule.c use the correct one.

Additionally copy over the modified fib_rules.h file

---
 include/uapi/linux/fib_rules.h |   2 +-
 ip/iprule.c                    | 132 ++++++++++++++++++++++-------------------
 2 files changed, 72 insertions(+), 62 deletions(-)
include/uapi/linux/fib_rules.h +1 -1
index 2b642bf9..92553917 100644
@@ -23,8 +23,8 @@ struct fib_rule_hdr {
 	__u8		tos;
 
 	__u8		table;
+	__u8		proto;
 	__u8		res1;	/* reserved */
-	__u8		res2;	/* reserved */
 	__u8		action;
 
 	__u32		flags;
ip/iprule.c +71 -61

321 lines not on this page · raw message

Signature · 1 line
2.14.3
#1 lore raw
Quoted 15 lines · Donald Sharp
ip/iprule.c +7 -1
@@ -159,7 +159,13 @@ static bool filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
 			return false;
 	}
 
-	table = rtm_get_table(r, tb);
+
+	/* struct fib_rule_hdr and struct rtmsg
+	 * were intentionally the same.  Since
+	 * the table is the rtm_table, just call
+	 * it.
+	 */
+	table = rtm_get_table((struct rtmsg *)frh, tb);
 	if (filter.tb > 0 && filter.tb ^ table)
 		return false;
 

...

Quoted 4 lines
ip/iprule.c +0 -0
@@ -273,7 +279,12 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 		fprintf(fp, "uidrange %u-%u ", r->start, r->end);
 	}
 

ip/iprule.c int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) · line 290

Quoted 10 lines
ip/iprule.c +6 -1
-	table = rtm_get_table(r, tb);
+	/* struct fib_rule_hdr and struct rtmsg
+	 * were intentionally the same.  Since
+	 * the table is the rtm_table, just call
+	 * it.
+	 */
+	table = rtm_get_table((struct rtmsg *)frh, tb);
 	if (table) {
 		fprintf(fp, "lookup %s ",
 			rtnl_rttable_n2a(table, b1, sizeof(b1)));

I would rather have a second get_table function than use the typecast; frh_get_table() that mirrors rtm_get_table.

Thanks for taking the time to fix the ancillary header struct.