From 4e4b78324f1dbcee590c01a7ac3e5ebaf20daa27 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Thu, 4 Jun 2015 09:01:18 -0300 Subject: [PATCH 1/4] Fix changing tunnel remote and local address to any If a tunnel is created with a local address, you can't change it to any. # ip tunnel add tunl1 mode ipip remote 10.16.42.37 local 10.16.42.214 ttl 64 # ip tunnel show tunl1 tunl1: ip/ip remote 10.16.42.37 local 10.16.42.214 ttl 64 # ip tunnel change tunl1 local any # echo $? 0 # ip tunnel show tunl1 tunl1: ip/ip remote 10.16.42.37 local 10.16.42.214 ttl 64 It happens that parse_args zeroes ip_tunnel_parm, and when creating the tunnel, it is OK to leave it as is if the address is any. However, when changing the tunnel, the current parameters will be read from ip_tunnel_parm, and local and remote address won't be zeroes anymore, so it needs to be explicitly set to any. Signed-off-by: Thadeu Lima de Souza Cascardo Acked-by: Nicolas Dichtel --- ip/iptunnel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ip/iptunnel.c b/ip/iptunnel.c index be84b83e..78fa9885 100644 --- a/ip/iptunnel.c +++ b/ip/iptunnel.c @@ -167,10 +167,14 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) NEXT_ARG(); if (strcmp(*argv, "any")) p->iph.daddr = get_addr32(*argv); + else + p->iph.daddr = htonl(INADDR_ANY); } else if (strcmp(*argv, "local") == 0) { NEXT_ARG(); if (strcmp(*argv, "any")) p->iph.saddr = get_addr32(*argv); + else + p->iph.saddr = htonl(INADDR_ANY); } else if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); strncpy(medium, *argv, IFNAMSIZ-1); From 45b01c46d420ed790f7733763060af1725735c05 Mon Sep 17 00:00:00 2001 From: Mazhar Rana Date: Thu, 11 Jun 2015 21:37:36 +0530 Subject: [PATCH 2/4] mroute: "ip mroute show" not working when "to" and/or "from" is given The command "ip mroute show" is not showing routes when "to" and/or "from" filter is applied. root@mazhar:~# ip mroute show (10.202.30.101, 235.1.2.3) Iif: eth0 Oifs: eth1 But When I applied filter, it does not show anything. root@mazhar:~# ip mroute show 235.1.2.3 from 10.202.30.101 root@mazhar:~# Signed-off-by: Mazhar Rana --- ip/ipmroute.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ip/ipmroute.c b/ip/ipmroute.c index 125a13f8..fffa9e2c 100644 --- a/ip/ipmroute.c +++ b/ip/ipmroute.c @@ -97,15 +97,25 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (filter.af && filter.af != r->rtm_family) return 0; - if (tb[RTA_DST] && - filter.mdst.bitlen > 0 && - inet_addr_match(RTA_DATA(tb[RTA_DST]), &filter.mdst, filter.mdst.bitlen)) - return 0; + if (tb[RTA_DST] && filter.mdst.bitlen > 0) { + inet_prefix dst; - if (tb[RTA_SRC] && - filter.msrc.bitlen > 0 && - inet_addr_match(RTA_DATA(tb[RTA_SRC]), &filter.msrc, filter.msrc.bitlen)) - return 0; + memset(&dst, 0, sizeof(dst)); + dst.family = r->rtm_family; + memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST])); + if (inet_addr_match(&dst, &filter.mdst, filter.mdst.bitlen)) + return 0; + } + + if (tb[RTA_SRC] && filter.msrc.bitlen > 0) { + inet_prefix src; + + memset(&src, 0, sizeof(src)); + src.family = r->rtm_family; + memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC])); + if (inet_addr_match(&src, &filter.msrc, filter.msrc.bitlen)) + return 0; + } family = r->rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6; From 0bbca0422f9779cc4eeaf70aa01dcad10d6ab076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 25 Jun 2015 02:03:02 -0700 Subject: [PATCH 3/4] iproute2: tc/m_pedit.c - remove dead code The initializers are simply not needed. These if-blocks are outright dead code, because '0 > unsigned' is always false, so only else clause triggers and regardless of which clause triggers it only updates 'ind' which is later unconditionally written to before being used anyway. Otherwise we get errors from clang: m_pedit.c:166:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare] if (0 > tkey->off) { ~ ^ ~~~~~~~~~ m_pedit.c:209:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare] if (0 > tkey->off) { ~ ^ ~~~~~~~~~ 2 errors generated. Change-Id: I3c9e9092915088fc56f992e5df736851541a4458 --- tc/m_pedit.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tc/m_pedit.c b/tc/m_pedit.c index dfe9b2eb..4fdd189d 100644 --- a/tc/m_pedit.c +++ b/tc/m_pedit.c @@ -160,17 +160,9 @@ pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) int pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) { - int ind = 0, stride = 0; + int ind, stride; __u32 m[4] = {0xFFFF0000,0xFF0000FF,0x0000FFFF}; - if (0 > tkey->off) { - ind = tkey->off + 1; - if (0 > ind) - ind = -1*ind; - } else { - ind = tkey->off; - } - if (tkey->val > 0xFFFF || tkey->mask > 0xFFFF) { fprintf(stderr, "pack_key16 bad value\n"); return -1; @@ -178,18 +170,16 @@ pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) ind = tkey->off & 3; - if (0 > ind || 2 < ind) { + if (ind == 3) { fprintf(stderr, "pack_key16 bad index value %d\n",ind); return -1; } stride = 8 * ind; tkey->val = htons(tkey->val); - if (stride > 0) { - tkey->val <<= stride; - tkey->mask <<= stride; - retain <<= stride; - } + tkey->val <<= stride; + tkey->mask <<= stride; + retain <<= stride; tkey->mask = retain|m[ind]; tkey->off &= ~3; @@ -203,28 +193,22 @@ pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) int pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) { - int ind = 0, stride = 0; + int ind, stride; __u32 m[4] = {0xFFFFFF00,0xFFFF00FF,0xFF00FFFF,0x00FFFFFF}; - if (0 > tkey->off) { - ind = tkey->off + 1; - if (0 > ind) - ind = -1*ind; - } else { - ind = tkey->off; - } - if (tkey->val > 0xFF || tkey->mask > 0xFF) { fprintf(stderr, "pack_key8 bad value (val %x mask %x\n", tkey->val, tkey->mask); return -1; } ind = tkey->off & 3; + stride = 8 * ind; tkey->val <<= stride; tkey->mask <<= stride; retain <<= stride; tkey->mask = retain|m[ind]; + tkey->off &= ~3; if (pedit_debug) From bbd303d183a5638be7feb952b6266a9251bce348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 25 Jun 2015 02:03:03 -0700 Subject: [PATCH 4/4] iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0 s->local.data is a pointer to a field of a non-NULL struct, and hence cannot be NULL, thus comparing it to 0 is always false, and thus the return is always false. Presumably this was meant to be a check whether s->local.data[0] (which I believe stores af_packet protocol) is 0, ie. ANY. Change-Id: Ia232f5b06ce081e3b2fb6338f1a709cd94e03ae5 Fixes: ss.c:1018:37: error: comparison of array 's->local.data' equal to a null pointer is always false [-Werror,-Wtautological-pointer-compare] return s->lport == 0 && s->local.data == 0; ~~~~~~~~~^~~~ ~ 1 error generated. --- misc/ss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/ss.c b/misc/ss.c index 1f4a30f7..748e6930 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -1081,7 +1081,7 @@ static int run_ssfilter(struct ssfilter *f, struct sockstat *s) strspn(p+1, "0123456789abcdef") == 5); } if (s->local.family == AF_PACKET) - return s->lport == 0 && s->local.data == 0; + return s->lport == 0 && s->local.data[0] == 0; if (s->local.family == AF_NETLINK) return s->lport < 0;