From: Romary Sonrier Date: Tue, 3 May 2011 09:26:21 +0000 (+0200) Subject: Adding rule with "From" option doesn't work X-Git-Tag: libnl3_1~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb6a089d80df51f8bcd1a1cf6637174fdf483954;p=libnl Adding rule with "From" option doesn't work OK i found the bug, is is the patch !! Can someone push it into the git tree ? Regards, Romary Sonrier ========================= My analysis: I guess that the pay load is *struct fib_rule_hdr* struct fib_rule_hdr { __u8 family; __u8 dst_len; __u8 src_len; __u8 tos; __u8 table; __u8 res1; /* reserved */ __u8 res2; /* reserved */ __u8 action; __u32 flags; }; > [PAYLOAD] 12 octets > 02 00 00 00 0a 00 00 01 00 00 00 00 ............ so family = 02 , fine table = 10, fine but src_len =0 !!!! should be 32 --- diff --git a/lib/route/rule.c b/lib/route/rule.c index 8fa54e9..1a695cd 100644 --- a/lib/route/rule.c +++ b/lib/route/rule.c @@ -374,18 +374,20 @@ static int build_rule_msg(struct rtnl_rule *tmpl, int cmd, int flags, if (!msg) return -NLE_NOMEM; + if (tmpl->ce_mask & RULE_ATTR_SRC) + frh.src_len = nl_addr_get_prefixlen(tmpl->r_src); + + if (tmpl->ce_mask & RULE_ATTR_DST) + frh.dst_len = nl_addr_get_prefixlen(tmpl->r_dst); + if (nlmsg_append(msg, &frh, sizeof(frh), NLMSG_ALIGNTO) < 0) goto nla_put_failure; - if (tmpl->ce_mask & RULE_ATTR_SRC) { - frh.src_len = nl_addr_get_prefixlen(tmpl->r_src); + if (tmpl->ce_mask & RULE_ATTR_SRC) NLA_PUT_ADDR(msg, FRA_SRC, tmpl->r_src); - } - if (tmpl->ce_mask & RULE_ATTR_DST) { - frh.dst_len = nl_addr_get_prefixlen(tmpl->r_dst); + if (tmpl->ce_mask & RULE_ATTR_DST) NLA_PUT_ADDR(msg, FRA_DST, tmpl->r_dst); - } if (tmpl->ce_mask & RULE_ATTR_IIFNAME) NLA_PUT_STRING(msg, FRA_IIFNAME, tmpl->r_iifname);