* Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: David Ahern @ 2016-03-22 18:29 UTC (permalink / raw)
To: Lance Richardson, netdev
In-Reply-To: <1458660679-7279-1-git-send-email-lrichard@redhat.com>
On 3/22/16 9:31 AM, Lance Richardson wrote:
> Field fl4.flowi4_flags is not initialized in fib_compute_spec_dst()
> before calling fib_lookup(), which means fib_table_lookup() is
> using non-deterministic data at this line:
>
> if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
>
> Fix by initializing fl4.flowi4_flags to zero.
>
> Signed-off-by: Lance Richardson <lrichard@redhat.com>
> ---
> net/ipv4/fib_frontend.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> index 21add55..896844a 100644
> --- a/net/ipv4/fib_frontend.c
> +++ b/net/ipv4/fib_frontend.c
> @@ -304,6 +304,7 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
> fl4.flowi4_scope = scope;
> fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
> fl4.flowi4_tun_key.tun_id = 0;
> + fl4.flowi4_flags = 0;
> if (!fib_lookup(net, &fl4, &res, 0))
> return FIB_RES_PREFSRC(net, res);
> } else {
>
Fixes: 58189ca7b2741 ("net: Fix vti use case with oif in dst lookups")
I think a more robust solution is to move fl4 to this if case and init
when it is declared:
struct flowi4 fl4 = {
.flowi4_iif = LOOPBACK_IFINDEX,
.daddr = ip_hdr(skb)->saddr,
.flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
.flowi4_scope = scope,
.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0,
};
^ permalink raw reply
* [iproute PATCH 5/7] lib/utils: introduce format_host_rta()
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
This simple macro eases calling format_host() with data from an rt_attr
pointer.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/utils.h | 2 ++
ip/ipaddress.c | 20 ++++++++------------
ip/ipaddrlabel.c | 5 ++---
ip/ipneigh.c | 4 +---
ip/iproute.c | 33 +++++++++++----------------------
ip/iproute_lwtunnel.c | 5 ++---
ip/iprule.c | 16 ++++++----------
ip/iptoken.c | 9 +++------
8 files changed, 35 insertions(+), 59 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index bc2cbce0cc303..ebb80c9c20b6d 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -125,6 +125,8 @@ int af_byte_len(int af);
const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen);
const char *format_host(int af, int lne, const void *addr);
+#define format_host_rta(af, rta) \
+ format_host(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
const char *rt_addr_n2a_r(int af, int len, const void *addr,
char *buf, int buflen);
const char *rt_addr_n2a(int af, int len, const void *addr);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 03c8c03cd4a17..3998d8cec4ab2 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1058,18 +1058,16 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (rta_tb[IFA_LOCAL]) {
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s",
- format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
- RTA_DATA(rta_tb[IFA_LOCAL])));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_LOCAL]));
if (rta_tb[IFA_ADDRESS] &&
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
RTA_DATA(rta_tb[IFA_LOCAL]),
ifa->ifa_family == AF_INET ? 4 : 16)) {
fprintf(fp, " peer ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family),
- "%s", format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
- RTA_DATA(rta_tb[IFA_ADDRESS])));
+ "%s", format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_ADDRESS]));
}
fprintf(fp, "/%d ", ifa->ifa_prefixlen);
}
@@ -1080,16 +1078,14 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (rta_tb[IFA_BROADCAST]) {
fprintf(fp, "brd ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
- format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
- RTA_DATA(rta_tb[IFA_BROADCAST])));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_BROADCAST]));
}
if (rta_tb[IFA_ANYCAST]) {
fprintf(fp, "any ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
- format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
- RTA_DATA(rta_tb[IFA_ANYCAST])));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_ANYCAST]));
}
fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
if (ifa_flags & IFA_F_SECONDARY) {
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 6076bb952297f..b4cd784094719 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -75,9 +75,8 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
if (tb[IFAL_ADDRESS]) {
fprintf(fp, "prefix %s/%u ",
- format_host(ifal->ifal_family,
- RTA_PAYLOAD(tb[IFAL_ADDRESS]),
- RTA_DATA(tb[IFAL_ADDRESS])),
+ format_host_rta(ifal->ifal_family,
+ tb[IFAL_ADDRESS]),
ifal->ifal_prefixlen);
}
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 583aad30dc820..c49fb4e7f7b58 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -278,9 +278,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "miss ");
if (tb[NDA_DST]) {
fprintf(fp, "%s ",
- format_host(r->ndm_family,
- RTA_PAYLOAD(tb[NDA_DST]),
- RTA_DATA(tb[NDA_DST])));
+ format_host_rta(r->ndm_family, tb[NDA_DST]));
}
if (!filter.index && r->ndm_ifindex)
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
diff --git a/ip/iproute.c b/ip/iproute.c
index 1ec9294290b2a..67d551b54d00c 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -376,10 +376,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
r->rtm_dst_len
);
} else {
- fprintf(fp, "%s ", format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]))
- );
+ fprintf(fp, "%s ",
+ format_host_rta(r->rtm_family, tb[RTA_DST]));
}
} else if (r->rtm_dst_len) {
fprintf(fp, "0/%d ", r->rtm_dst_len);
@@ -394,19 +392,15 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
r->rtm_src_len
);
} else {
- fprintf(fp, "from %s ", format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]))
- );
+ fprintf(fp, "from %s ",
+ format_host_rta(r->rtm_family, tb[RTA_SRC]));
}
} else if (r->rtm_src_len) {
fprintf(fp, "from 0/%u ", r->rtm_src_len);
}
if (tb[RTA_NEWDST]) {
- fprintf(fp, "as to %s ", format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_NEWDST]),
- RTA_DATA(tb[RTA_NEWDST]))
- );
+ fprintf(fp, "as to %s ",
+ format_host_rta(r->rtm_family, tb[RTA_NEWDST]));
}
if (tb[RTA_ENCAP])
@@ -419,9 +413,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) {
fprintf(fp, "via %s ",
- format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY])));
+ format_host_rta(r->rtm_family, tb[RTA_GATEWAY]));
}
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
@@ -653,16 +645,13 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
tb[RTA_ENCAP]);
if (tb[RTA_NEWDST]) {
fprintf(fp, " as to %s ",
- format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_NEWDST]),
- RTA_DATA(tb[RTA_NEWDST]),
- abuf, sizeof(abuf)));
+ format_host_rta(r->rtm_family,
+ tb[RTA_NEWDST]));
}
if (tb[RTA_GATEWAY]) {
fprintf(fp, " via %s ",
- format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY])));
+ format_host_rta(r->rtm_family,
+ tb[RTA_GATEWAY]));
}
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 53d3ad4e6ea8e..56af9e4e92ecd 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -62,9 +62,8 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap)
parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap);
if (tb[MPLS_IPTUNNEL_DST])
- fprintf(fp, " %s ", format_host(AF_MPLS,
- RTA_PAYLOAD(tb[MPLS_IPTUNNEL_DST]),
- RTA_DATA(tb[MPLS_IPTUNNEL_DST])));
+ fprintf(fp, " %s ",
+ format_host_rta(AF_MPLS, tb[MPLS_IPTUNNEL_DST]));
}
static void print_encap_ip(FILE *fp, struct rtattr *encap)
diff --git a/ip/iprule.c b/ip/iprule.c
index 3fd510efe5e1b..ac570440d6633 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -89,10 +89,8 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
r->rtm_src_len
);
} else {
- fprintf(fp, "from %s ", format_host(r->rtm_family,
- RTA_PAYLOAD(tb[FRA_SRC]),
- RTA_DATA(tb[FRA_SRC]))
- );
+ fprintf(fp, "from %s ",
+ format_host_rta(r->rtm_family, tb[FRA_SRC]));
}
} else if (r->rtm_src_len) {
fprintf(fp, "from 0/%d ", r->rtm_src_len);
@@ -108,9 +106,8 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
r->rtm_dst_len
);
} else {
- fprintf(fp, "to %s ", format_host(r->rtm_family,
- RTA_PAYLOAD(tb[FRA_DST]),
- RTA_DATA(tb[FRA_DST])));
+ fprintf(fp, "to %s ",
+ format_host_rta(r->rtm_family, tb[FRA_DST]));
}
} else if (r->rtm_dst_len) {
fprintf(fp, "to 0/%d ", r->rtm_dst_len);
@@ -183,9 +180,8 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_type == RTN_NAT) {
if (tb[RTA_GATEWAY]) {
fprintf(fp, "map-to %s ",
- format_host(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY])));
+ format_host_rta(r->rtm_family,
+ tb[RTA_GATEWAY]));
} else
fprintf(fp, "masquerade");
} else if (r->rtm_type == FR_ACT_GOTO) {
diff --git a/ip/iptoken.c b/ip/iptoken.c
index 02fe98e249526..6e1a1ab7f36e7 100644
--- a/ip/iptoken.c
+++ b/ip/iptoken.c
@@ -78,12 +78,9 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
return -1;
}
- fprintf(fp, "token %s ",
- format_host(ifi->ifi_family,
- RTA_PAYLOAD(ltb[IFLA_INET6_TOKEN]),
- RTA_DATA(ltb[IFLA_INET6_TOKEN])));
- fprintf(fp, "dev %s ", ll_index_to_name(ifi->ifi_index));
- fprintf(fp, "\n");
+ fprintf(fp, "token %s dev %s\n",
+ format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN]),
+ ll_index_to_name(ifi->ifi_index));
fflush(fp);
return 0;
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 6/7] lib/utils: introduce rt_addr_n2a_rta()
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
This simple macro eases calling rt_addr_n2a() with data from an rt_attr
pointer.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/utils.h | 2 ++
ip/iplink_bond.c | 4 +---
ip/ipmroute.c | 8 ++------
ip/ipprefix.c | 14 +++-----------
ip/iproute.c | 20 +++++++-------------
ip/iproute_lwtunnel.c | 19 ++++---------------
ip/iprule.c | 16 ++++++----------
ip/link_ip6tnl.c | 8 ++------
tc/f_flower.c | 8 ++------
9 files changed, 29 insertions(+), 70 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index ebb80c9c20b6d..ef81d00f3d70d 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -130,6 +130,8 @@ const char *format_host(int af, int lne, const void *addr);
const char *rt_addr_n2a_r(int af, int len, const void *addr,
char *buf, int buflen);
const char *rt_addr_n2a(int af, int len, const void *addr);
+#define rt_addr_n2a_rta(af, rta) \
+ rt_addr_n2a(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
int read_family(const char *name);
const char *family_name(int family);
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 7da58e4556c07..fe83479a091a8 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -422,9 +422,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
if (iptb[i])
fprintf(f, "%s",
- rt_addr_n2a(AF_INET,
- RTA_PAYLOAD(iptb[i]),
- RTA_DATA(iptb[i])));
+ rt_addr_n2a_rta(AF_INET, iptb[i]));
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
fprintf(f, ",");
}
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index 2b9f892a62630..c33cdcbbde21b 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -123,16 +123,12 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_SRC])
len = snprintf(obuf, sizeof(obuf),
- "(%s, ", rt_addr_n2a(family,
- RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC])));
+ "(%s, ", rt_addr_n2a_rta(family, tb[RTA_SRC]));
else
len = sprintf(obuf, "(unknown, ");
if (tb[RTA_DST])
snprintf(obuf + len, sizeof(obuf) - len,
- "%s)", rt_addr_n2a(family,
- RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST])));
+ "%s)", rt_addr_n2a_rta(family, tb[RTA_DST]));
else
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
diff --git a/ip/ipprefix.c b/ip/ipprefix.c
index 4d986dbc1a5d1..a833efcf67c4a 100644
--- a/ip/ipprefix.c
+++ b/ip/ipprefix.c
@@ -71,19 +71,11 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
parse_rtattr(tb, RTA_MAX, RTM_RTA(prefix), len);
- fprintf(fp, "prefix ");
-
if (tb[PREFIX_ADDRESS]) {
- struct in6_addr *pfx;
-
- pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
-
- fprintf(fp, "%s", rt_addr_n2a(family,
- RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
- pfx));
+ fprintf(fp, "prefix %s/%u",
+ rt_addr_n2a_rta(family, tb[PREFIX_ADDRESS]),
+ prefix->prefix_len);
}
- fprintf(fp, "/%u ", prefix->prefix_len);
-
fprintf(fp, "dev %s ", ll_index_to_name(prefix->prefix_ifindex));
if (prefix->prefix_flags & IF_PREFIX_ONLINK)
diff --git a/ip/iproute.c b/ip/iproute.c
index 67d551b54d00c..8224d7ffa94bf 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -370,11 +370,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_DST]) {
if (r->rtm_dst_len != host_len) {
- fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST])),
- r->rtm_dst_len
- );
+ fprintf(fp, "%s/%u ",
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_DST]),
+ r->rtm_dst_len);
} else {
fprintf(fp, "%s ",
format_host_rta(r->rtm_family, tb[RTA_DST]));
@@ -386,11 +384,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[RTA_SRC]) {
if (r->rtm_src_len != host_len) {
- fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC])),
- r->rtm_src_len
- );
+ fprintf(fp, "from %s/%u ",
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_SRC]),
+ r->rtm_src_len);
} else {
fprintf(fp, "from %s ",
format_host_rta(r->rtm_family, tb[RTA_SRC]));
@@ -439,9 +435,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
and symbolic name will not be useful.
*/
fprintf(fp, " src %s ",
- rt_addr_n2a(r->rtm_family,
- RTA_PAYLOAD(tb[RTA_PREFSRC]),
- RTA_DATA(tb[RTA_PREFSRC])));
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_PREFSRC]));
}
if (tb[RTA_PRIORITY])
fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 56af9e4e92ecd..3baac77208168 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -77,15 +77,11 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)
if (tb[LWTUNNEL_IP_SRC])
fprintf(fp, "src %s ",
- rt_addr_n2a(AF_INET,
- RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
- RTA_DATA(tb[LWTUNNEL_IP_SRC])));
+ rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_SRC]));
if (tb[LWTUNNEL_IP_DST])
fprintf(fp, "dst %s ",
- rt_addr_n2a(AF_INET,
- RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
- RTA_DATA(tb[LWTUNNEL_IP_DST])));
+ rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_DST]));
if (tb[LWTUNNEL_IP_TTL])
fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
@@ -112,7 +108,6 @@ static void print_encap_ila(FILE *fp, struct rtattr *encap)
static void print_encap_ip6(FILE *fp, struct rtattr *encap)
{
struct rtattr *tb[LWTUNNEL_IP6_MAX+1];
- char abuf[256];
parse_rtattr_nested(tb, LWTUNNEL_IP6_MAX, encap);
@@ -121,17 +116,11 @@ static void print_encap_ip6(FILE *fp, struct rtattr *encap)
if (tb[LWTUNNEL_IP6_SRC])
fprintf(fp, "src %s ",
- rt_addr_n2a(AF_INET6,
- RTA_PAYLOAD(tb[LWTUNNEL_IP6_SRC]),
- RTA_DATA(tb[LWTUNNEL_IP6_SRC]),
- abuf, sizeof(abuf)));
+ rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_SRC]));
if (tb[LWTUNNEL_IP6_DST])
fprintf(fp, "dst %s ",
- rt_addr_n2a(AF_INET6,
- RTA_PAYLOAD(tb[LWTUNNEL_IP6_DST]),
- RTA_DATA(tb[LWTUNNEL_IP6_DST]),
- abuf, sizeof(abuf)));
+ rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_DST]));
if (tb[LWTUNNEL_IP6_HOPLIMIT])
fprintf(fp, "hoplimit %d ", rta_getattr_u8(tb[LWTUNNEL_IP6_HOPLIMIT]));
diff --git a/ip/iprule.c b/ip/iprule.c
index ac570440d6633..7cb19e4d5ebd0 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -83,11 +83,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_SRC]) {
if (r->rtm_src_len != host_len) {
- fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_PAYLOAD(tb[FRA_SRC]),
- RTA_DATA(tb[FRA_SRC])),
- r->rtm_src_len
- );
+ fprintf(fp, "from %s/%u ",
+ rt_addr_n2a_rta(r->rtm_family, tb[FRA_SRC]),
+ r->rtm_src_len);
} else {
fprintf(fp, "from %s ",
format_host_rta(r->rtm_family, tb[FRA_SRC]));
@@ -100,11 +98,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_DST]) {
if (r->rtm_dst_len != host_len) {
- fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
- RTA_PAYLOAD(tb[FRA_DST]),
- RTA_DATA(tb[FRA_DST])),
- r->rtm_dst_len
- );
+ fprintf(fp, "to %s/%u ",
+ rt_addr_n2a_rta(r->rtm_family, tb[FRA_DST]),
+ r->rtm_dst_len);
} else {
fprintf(fp, "to %s ",
format_host_rta(r->rtm_family, tb[FRA_DST]));
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index 4b32fe5aa8088..8a31d0dcd1883 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -289,16 +289,12 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
if (tb[IFLA_IPTUN_REMOTE]) {
fprintf(f, "remote %s ",
- rt_addr_n2a(AF_INET6,
- RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
- RTA_DATA(tb[IFLA_IPTUN_REMOTE])));
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
}
if (tb[IFLA_IPTUN_LOCAL]) {
fprintf(f, "local %s ",
- rt_addr_n2a(AF_INET6,
- RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
- RTA_DATA(tb[IFLA_IPTUN_LOCAL])));
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
}
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 40f8c595b2eec..306f056c1b662 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -415,16 +415,12 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
}
if (!addr_attr || RTA_PAYLOAD(addr_attr) != len)
return;
- fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
- RTA_PAYLOAD(addr_attr),
- RTA_DATA(addr_attr)));
+ fprintf(f, "\n %s %s", name, rt_addr_n2a_rta(family, addr_attr));
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
return;
bits = __mask_bits(RTA_DATA(mask_attr), len);
if (bits < 0)
- fprintf(f, "/%s", rt_addr_n2a(family,
- RTA_PAYLOAD(mask_attr),
- RTA_DATA(mask_attr)));
+ fprintf(f, "/%s", rt_addr_n2a_rta(family, mask_attr));
else if (bits < len * 8)
fprintf(f, "/%d", bits);
}
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 3/7] make format_host non-reentrant by default
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
There are only three users which require it to be reentrant, the rest is
fine without. Instead, provide a reentrant format_host_r() for users
which need it.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
bridge/fdb.c | 4 +---
include/utils.h | 3 ++-
ip/ip6tunnel.c | 2 +-
ip/ipaddress.c | 13 ++++---------
ip/ipaddrlabel.c | 4 +---
ip/iplink_geneve.c | 5 ++---
ip/iplink_vxlan.c | 13 ++++++-------
ip/ipmaddr.c | 6 +-----
ip/ipneigh.c | 4 +---
ip/iproute.c | 21 +++++++--------------
ip/iproute_lwtunnel.c | 4 +---
ip/iprule.c | 9 +++------
ip/iptoken.c | 4 +---
ip/iptunnel.c | 6 +++---
ip/link_gre.c | 5 ++---
ip/link_gre6.c | 5 ++---
ip/link_iptnl.c | 7 +++----
ip/link_vti.c | 5 ++---
ip/link_vti6.c | 5 ++---
ip/tcp_metrics.c | 6 ++----
lib/utils.c | 9 ++++++++-
misc/ss.c | 4 ++--
tc/m_nat.c | 4 ++--
23 files changed, 59 insertions(+), 89 deletions(-)
diff --git a/bridge/fdb.c b/bridge/fdb.c
index 88f1b63c233e9..e8c314a3c0771 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -104,7 +104,6 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
if (tb[NDA_DST]) {
- SPRINT_BUF(abuf);
int family = AF_INET;
if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
@@ -113,8 +112,7 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "dst %s ",
format_host(family,
RTA_PAYLOAD(tb[NDA_DST]),
- RTA_DATA(tb[NDA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[NDA_DST])));
}
if (tb[NDA_VLAN]) {
diff --git a/include/utils.h b/include/utils.h
index c43427c35a6cc..84083b0dbba71 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -122,8 +122,9 @@ int addr64_n2a(__u64 addr, char *buff, size_t len);
int af_bit_len(int af);
int af_byte_len(int af);
-const char *format_host(int af, int len, const void *addr,
+const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen);
+const char *format_host(int af, int lne, const void *addr);
const char *rt_addr_n2a(int af, int len, const void *addr,
char *buf, int buflen);
diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index 2e9d3ed40d003..d588645eb942a 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -77,7 +77,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
printf("%s: %s/ipv6 remote %s local %s",
p->name,
tnl_strproto(p->proto),
- format_host(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
+ format_host_r(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
if (p->link) {
const char *n = ll_index_to_name(p->link);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 90d7b1096c3aa..03c8c03cd4a17 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -964,7 +964,6 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
/* Use local copy of ifa_flags to not interfere with filtering code */
unsigned int ifa_flags;
struct rtattr *rta_tb[IFA_MAX+1];
- char abuf[256];
SPRINT_BUF(b1);
@@ -1061,8 +1060,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s",
format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
- RTA_DATA(rta_tb[IFA_LOCAL]),
- abuf, sizeof(abuf)));
+ RTA_DATA(rta_tb[IFA_LOCAL])));
if (rta_tb[IFA_ADDRESS] &&
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
RTA_DATA(rta_tb[IFA_LOCAL]),
@@ -1071,8 +1069,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family),
"%s", format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
- RTA_DATA(rta_tb[IFA_ADDRESS]),
- abuf, sizeof(abuf)));
+ RTA_DATA(rta_tb[IFA_ADDRESS])));
}
fprintf(fp, "/%d ", ifa->ifa_prefixlen);
}
@@ -1085,16 +1082,14 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
- RTA_DATA(rta_tb[IFA_BROADCAST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(rta_tb[IFA_BROADCAST])));
}
if (rta_tb[IFA_ANYCAST]) {
fprintf(fp, "any ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
- RTA_DATA(rta_tb[IFA_ANYCAST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(rta_tb[IFA_ANYCAST])));
}
fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
if (ifa_flags & IFA_F_SECONDARY) {
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 05c44978ff37a..6076bb952297f 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -60,7 +60,6 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
struct ifaddrlblmsg *ifal = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[IFAL_MAX+1];
- char abuf[256];
if (n->nlmsg_type != RTM_NEWADDRLABEL && n->nlmsg_type != RTM_DELADDRLABEL)
return 0;
@@ -78,8 +77,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
fprintf(fp, "prefix %s/%u ",
format_host(ifal->ifal_family,
RTA_PAYLOAD(tb[IFAL_ADDRESS]),
- RTA_DATA(tb[IFAL_ADDRESS]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[IFAL_ADDRESS])),
ifal->ifal_prefixlen);
}
diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c
index 40c08ec270d15..c6e7bbe0ce20e 100644
--- a/ip/iplink_geneve.c
+++ b/ip/iplink_geneve.c
@@ -138,7 +138,6 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
__u32 vni;
- char s1[1024];
__u8 tos;
if (!tb)
@@ -156,7 +155,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr)
fprintf(f, "remote %s ",
- format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
+ format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_GENEVE_REMOTE6]) {
struct in6_addr addr;
@@ -164,7 +163,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr))
fprintf(f, "remote %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
+ format_host(AF_INET6, sizeof(struct in6_addr), &addr));
}
}
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index 5c23cf534ce81..543522e139ff4 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -310,7 +310,6 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int link;
__u8 tos;
__u32 maxaddr;
- char s1[1024];
char s2[64];
if (!tb)
@@ -329,10 +328,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr) {
if (IN_MULTICAST(ntohl(addr)))
fprintf(f, "group %s ",
- format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
+ format_host(AF_INET, 4, &addr));
else
fprintf(f, "remote %s ",
- format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
+ format_host(AF_INET, 4, &addr));
}
} else if (tb[IFLA_VXLAN_GROUP6]) {
struct in6_addr addr;
@@ -341,10 +340,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr))
fprintf(f, "group %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
+ format_host(AF_INET6, sizeof(struct in6_addr), &addr));
else
fprintf(f, "remote %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
+ format_host(AF_INET6, sizeof(struct in6_addr), &addr));
}
}
@@ -353,14 +352,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr)
fprintf(f, "local %s ",
- format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
+ format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_VXLAN_LOCAL6]) {
struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
fprintf(f, "local %s ",
- format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
+ format_host(AF_INET6, sizeof(struct in6_addr), &addr));
}
if (tb[IFLA_VXLAN_LINK] &&
diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 347990b5c8f52..c3673979f9761 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -204,8 +204,6 @@ static void print_maddr(FILE *fp, struct ma_info *list)
list->addr.bytelen, 0,
b1, sizeof(b1)));
} else {
- char abuf[256];
-
switch (list->addr.family) {
case AF_INET:
fprintf(fp, "inet ");
@@ -219,9 +217,7 @@ static void print_maddr(FILE *fp, struct ma_info *list)
}
fprintf(fp, "%s",
format_host(list->addr.family,
- -1,
- list->addr.data,
- abuf, sizeof(abuf)));
+ -1, list->addr.data));
}
if (list->users != 1)
fprintf(fp, " users %d", list->users);
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 6458c8eaa6b1e..583aad30dc820 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -198,7 +198,6 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
struct ndmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[NDA_MAX+1];
- char abuf[256];
static int logit = 1;
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH &&
@@ -281,8 +280,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "%s ",
format_host(r->ndm_family,
RTA_PAYLOAD(tb[NDA_DST]),
- RTA_DATA(tb[NDA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[NDA_DST])));
}
if (!filter.index && r->ndm_ifindex)
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
diff --git a/ip/iproute.c b/ip/iproute.c
index 19b28701d4da1..8315ad3e6c6ac 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -380,8 +380,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else {
fprintf(fp, "%s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf))
+ RTA_DATA(tb[RTA_DST]))
);
}
} else if (r->rtm_dst_len) {
@@ -400,8 +399,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else {
fprintf(fp, "from %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf))
+ RTA_DATA(tb[RTA_SRC]))
);
}
} else if (r->rtm_src_len) {
@@ -410,8 +408,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_NEWDST]) {
fprintf(fp, "as to %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_NEWDST]),
- RTA_DATA(tb[RTA_NEWDST]),
- abuf, sizeof(abuf))
+ RTA_DATA(tb[RTA_NEWDST]))
);
}
@@ -427,8 +424,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s ",
format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_GATEWAY])));
}
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
@@ -436,8 +432,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s %s ",
family_name(via->rtvia_family),
- format_host(via->rtvia_family, len, via->rtvia_addr,
- abuf, sizeof(abuf)));
+ format_host(via->rtvia_family, len, via->rtvia_addr));
}
if (tb[RTA_OIF] && filter.oifmask != -1)
fprintf(fp, "dev %s ", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_OIF])));
@@ -671,8 +666,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " via %s ",
format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_GATEWAY])));
}
if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
@@ -680,8 +674,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s %s ",
family_name(via->rtvia_family),
- format_host(via->rtvia_family, len, via->rtvia_addr,
- abuf, sizeof(abuf)));
+ format_host(via->rtvia_family, len, via->rtvia_addr));
}
if (tb[RTA_FLOW]) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]);
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index a53e11d9478e9..42abe3753ac6a 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -58,15 +58,13 @@ static const char *format_encap_type(int type)
static void print_encap_mpls(FILE *fp, struct rtattr *encap)
{
struct rtattr *tb[MPLS_IPTUNNEL_MAX+1];
- char abuf[256];
parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap);
if (tb[MPLS_IPTUNNEL_DST])
fprintf(fp, " %s ", format_host(AF_MPLS,
RTA_PAYLOAD(tb[MPLS_IPTUNNEL_DST]),
- RTA_DATA(tb[MPLS_IPTUNNEL_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[MPLS_IPTUNNEL_DST])));
}
static void print_encap_ip(FILE *fp, struct rtattr *encap)
diff --git a/ip/iprule.c b/ip/iprule.c
index dc45c6b43e606..345b3b042307d 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -94,8 +94,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else {
fprintf(fp, "from %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[FRA_SRC]),
- RTA_DATA(tb[FRA_SRC]),
- abuf, sizeof(abuf))
+ RTA_DATA(tb[FRA_SRC]))
);
}
} else if (r->rtm_src_len) {
@@ -115,8 +114,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else {
fprintf(fp, "to %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[FRA_DST]),
- RTA_DATA(tb[FRA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[FRA_DST])));
}
} else if (r->rtm_dst_len) {
fprintf(fp, "to 0/%d ", r->rtm_dst_len);
@@ -191,8 +189,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "map-to %s ",
format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]),
- RTA_DATA(tb[RTA_GATEWAY]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_GATEWAY])));
} else
fprintf(fp, "masquerade");
} else if (r->rtm_type == FR_ACT_GOTO) {
diff --git a/ip/iptoken.c b/ip/iptoken.c
index 1d22c03c63ab7..02fe98e249526 100644
--- a/ip/iptoken.c
+++ b/ip/iptoken.c
@@ -51,7 +51,6 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
int len = n->nlmsg_len;
struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *ltb[IFLA_INET6_MAX + 1];
- char abuf[256];
if (n->nlmsg_type != RTM_NEWLINK)
return -1;
@@ -82,8 +81,7 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
fprintf(fp, "token %s ",
format_host(ifi->ifi_family,
RTA_PAYLOAD(ltb[IFLA_INET6_TOKEN]),
- RTA_DATA(ltb[IFLA_INET6_TOKEN]),
- abuf, sizeof(abuf)));
+ RTA_DATA(ltb[IFLA_INET6_TOKEN])));
fprintf(fp, "dev %s ", ll_index_to_name(ifi->ifi_index));
fprintf(fp, "\n");
fflush(fp);
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index 65a4e6e9c1a5a..bfee99561615a 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -308,7 +308,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
printf("%s: %s/ip remote %s local %s",
p->name,
tnl_strproto(p->iph.protocol),
- p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
+ p->iph.daddr ? format_host_r(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
@@ -324,7 +324,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
if (prl[i].addr != htonl(INADDR_ANY)) {
printf(" %s %s ",
(prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
- format_host(AF_INET, 4, &prl[i].addr, s1, sizeof(s1)));
+ format_host(AF_INET, 4, &prl[i].addr));
}
}
}
@@ -360,7 +360,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
ip6rd.prefixlen);
if (ip6rd.relay_prefix) {
printf(" 6rd-relay_prefix %s/%u",
- format_host(AF_INET, 4, &ip6rd.relay_prefix, s1, sizeof(s1)),
+ format_host(AF_INET, 4, &ip6rd.relay_prefix),
ip6rd.relay_prefixlen);
}
}
diff --git a/ip/link_gre.c b/ip/link_gre.c
index c50963d79d3c5..bcf003aaa5d7a 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -339,7 +339,6 @@ get_failed:
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[1024];
char s2[64];
const char *local = "any";
const char *remote = "any";
@@ -353,7 +352,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
if (addr)
- remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ remote = format_host(AF_INET, 4, &addr);
}
fprintf(f, "remote %s ", remote);
@@ -362,7 +361,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
if (addr)
- local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ local = format_host(AF_INET, 4, &addr);
}
fprintf(f, "local %s ", local);
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index a48ea8b1ebae3..bddfc0ff97aa0 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -302,7 +302,6 @@ get_failed:
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[1024];
char s2[64];
const char *local = "any";
const char *remote = "any";
@@ -327,7 +326,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
- remote = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
+ remote = format_host(AF_INET6, sizeof(addr), &addr);
}
fprintf(f, "remote %s ", remote);
@@ -338,7 +337,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
- local = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
+ local = format_host(AF_INET6, sizeof(addr), &addr);
}
fprintf(f, "local %s ", local);
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 04568ffbd81bf..8411a6a00a1b4 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -339,7 +339,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
if (addr)
- remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ remote = format_host(AF_INET, 4, &addr);
}
fprintf(f, "remote %s ", remote);
@@ -348,7 +348,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]);
if (addr)
- local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ local = format_host(AF_INET, 4, &addr);
}
fprintf(f, "local %s ", local);
@@ -404,8 +404,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
prefixlen);
if (relayprefix) {
printf("6rd-relay_prefix %s/%u ",
- format_host(AF_INET, 4, &relayprefix, s1,
- sizeof(s1)),
+ format_host(AF_INET, 4, &relayprefix),
relayprefixlen);
}
}
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 587993035e8d5..8052e7514989a 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -198,7 +198,6 @@ get_failed:
static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[1024];
char s2[64];
const char *local = "any";
const char *remote = "any";
@@ -210,7 +209,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]);
if (addr)
- remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ remote = format_host(AF_INET, 4, &addr);
}
fprintf(f, "remote %s ", remote);
@@ -219,7 +218,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]);
if (addr)
- local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
+ local = format_host(AF_INET, 4, &addr);
}
fprintf(f, "local %s ", local);
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index 9a62eb5aa370d..9bcf7fe9dea46 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -197,7 +197,6 @@ get_failed:
static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[1024];
char s2[64];
const char *local = "any";
const char *remote = "any";
@@ -210,7 +209,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VTI_REMOTE]) {
memcpy(&daddr, RTA_DATA(tb[IFLA_VTI_REMOTE]), sizeof(daddr));
- remote = format_host(AF_INET6, 16, &daddr, s1, sizeof(s1));
+ remote = format_host(AF_INET6, 16, &daddr);
}
fprintf(f, "remote %s ", remote);
@@ -218,7 +217,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VTI_LOCAL]) {
memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr));
- local = format_host(AF_INET6, 16, &saddr, s1, sizeof(s1));
+ local = format_host(AF_INET6, 16, &saddr);
}
fprintf(f, "local %s ", local);
diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
index 3a649917191a8..f82604f458ada 100644
--- a/ip/tcp_metrics.c
+++ b/ip/tcp_metrics.c
@@ -95,7 +95,6 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
struct genlmsghdr *ghdr;
struct rtattr *attrs[TCP_METRICS_ATTR_MAX + 1], *a;
int len = n->nlmsg_len;
- char abuf[256];
inet_prefix daddr, saddr;
int family, i, atype, stype, dlen = 0, slen = 0;
@@ -194,7 +193,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "Deleted ");
fprintf(fp, "%s",
- format_host(family, dlen, &daddr.data, abuf, sizeof(abuf)));
+ format_host(family, dlen, &daddr.data));
a = attrs[TCP_METRICS_ATTR_AGE];
if (a) {
@@ -298,8 +297,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (slen) {
fprintf(fp, " source %s",
- format_host(family, slen, &saddr.data, abuf,
- sizeof(abuf)));
+ format_host(family, slen, &saddr.data));
}
fprintf(fp, "\n");
diff --git a/lib/utils.c b/lib/utils.c
index fa35f4d044064..22a5ef8fa8213 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -818,7 +818,7 @@ static const char *resolve_address(const void *addr, int len, int af)
}
#endif
-const char *format_host(int af, int len, const void *addr,
+const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen)
{
#ifdef RESOLVE_HOSTNAMES
@@ -835,6 +835,13 @@ const char *format_host(int af, int len, const void *addr,
return rt_addr_n2a(af, len, addr, buf, buflen);
}
+const char *format_host(int af, int len, const void *addr)
+{
+ static char buf[256];
+
+ return format_host_r(af, len, addr, buf, 256);
+}
+
char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen)
{
diff --git a/misc/ss.c b/misc/ss.c
index 192389cc82371..38cf3312a746e 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1016,10 +1016,10 @@ static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex
buf[0] = '*';
buf[1] = 0;
} else {
- ap = format_host(AF_INET, 4, a->data, buf, sizeof(buf));
+ ap = format_host(AF_INET, 4, a->data);
}
} else {
- ap = format_host(a->family, 16, a->data, buf, sizeof(buf));
+ ap = format_host(a->family, 16, a->data);
est_len = strlen(ap);
if (est_len <= addr_width)
est_len = addr_width;
diff --git a/tc/m_nat.c b/tc/m_nat.c
index deb071da90daf..4b90121c4b99e 100644
--- a/tc/m_nat.c
+++ b/tc/m_nat.c
@@ -191,9 +191,9 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
"egress" : "ingress",
- format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
+ format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
len,
- format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
+ format_host_r(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
action_n2a(sel->action, buf3, sizeof(buf3)));
if (show_stats) {
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 7/7] lib/ll_addr: improve ll_addr_n2a() a bit
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
Apart from making the code a bit more compact and efficient, this also
prevents a potential buffer overflow if the passed buffer is really too
small: Although correctly decrementing the size parameter passed to
snprintf, it could become negative which would then wrap since snprintf
uses (unsigned) size_t for the parameter.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
lib/ll_addr.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/lib/ll_addr.c b/lib/ll_addr.c
index 2ce9abfbb8c69..465ed6fa4d9a2 100644
--- a/lib/ll_addr.c
+++ b/lib/ll_addr.c
@@ -41,18 +41,9 @@ const char *ll_addr_n2a(const unsigned char *addr, int alen, int type, char *buf
if (alen == 16 && type == ARPHRD_TUNNEL6) {
return inet_ntop(AF_INET6, addr, buf, blen);
}
- l = 0;
- for (i=0; i<alen; i++) {
- if (i==0) {
- snprintf(buf+l, blen, "%02x", addr[i]);
- blen -= 2;
- l += 2;
- } else {
- snprintf(buf+l, blen, ":%02x", addr[i]);
- blen -= 3;
- l += 3;
- }
- }
+ snprintf(buf, blen, "%02x", addr[0]);
+ for (i = 1, l = 2; i < alen && l < blen; i++, l += 3)
+ snprintf(buf + l, blen - l, ":%02x", addr[i]);
return buf;
}
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 4/7] utils: make rt_addr_n2a() non-reentrant by default
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
There is only a single user who needs it to be reentrant (not really,
but it's safer like this), add rt_addr_n2a_r() for it to use.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/utils.h | 3 ++-
ip/ip6tunnel.c | 2 +-
ip/iplink_bond.c | 5 +----
ip/ipmroute.c | 7 ++-----
ip/ipprefix.c | 5 +----
ip/iproute.c | 10 +++-------
ip/iproute_lwtunnel.c | 7 ++-----
ip/iprule.c | 8 ++------
ip/iptunnel.c | 2 +-
ip/ipxfrm.c | 29 ++++++-----------------------
ip/link_ip6tnl.c | 7 ++-----
ip/xfrm_monitor.c | 16 +++-------------
lib/utils.c | 11 +++++++++--
tc/f_flower.c | 7 ++-----
14 files changed, 37 insertions(+), 82 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index 84083b0dbba71..bc2cbce0cc303 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -125,8 +125,9 @@ int af_byte_len(int af);
const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen);
const char *format_host(int af, int lne, const void *addr);
-const char *rt_addr_n2a(int af, int len, const void *addr,
+const char *rt_addr_n2a_r(int af, int len, const void *addr,
char *buf, int buflen);
+const char *rt_addr_n2a(int af, int len, const void *addr);
int read_family(const char *name);
const char *family_name(int family);
diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
index d588645eb942a..c02fa0746ab69 100644
--- a/ip/ip6tunnel.c
+++ b/ip/ip6tunnel.c
@@ -78,7 +78,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
p->name,
tnl_strproto(p->proto),
format_host_r(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
- rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
+ rt_addr_n2a_r(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
if (p->link) {
const char *n = ll_index_to_name(p->link);
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 45473f66da065..7da58e4556c07 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -411,7 +411,6 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_BOND_ARP_IP_TARGET]) {
struct rtattr *iptb[BOND_MAX_ARP_TARGETS + 1];
- char buf[INET_ADDRSTRLEN];
int i;
parse_rtattr_nested(iptb, BOND_MAX_ARP_TARGETS,
@@ -425,9 +424,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "%s",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(iptb[i]),
- RTA_DATA(iptb[i]),
- buf,
- INET_ADDRSTRLEN));
+ RTA_DATA(iptb[i])));
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
fprintf(f, ",");
}
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
index 34543c00ecb75..2b9f892a62630 100644
--- a/ip/ipmroute.c
+++ b/ip/ipmroute.c
@@ -58,7 +58,6 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[RTA_MAX+1];
- char abuf[256];
char obuf[256];
SPRINT_BUF(b1);
@@ -126,16 +125,14 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
len = snprintf(obuf, sizeof(obuf),
"(%s, ", rt_addr_n2a(family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_SRC])));
else
len = sprintf(obuf, "(unknown, ");
if (tb[RTA_DST])
snprintf(obuf + len, sizeof(obuf) - len,
"%s)", rt_addr_n2a(family,
RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_DST])));
else
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
diff --git a/ip/ipprefix.c b/ip/ipprefix.c
index 2524f784965b5..4d986dbc1a5d1 100644
--- a/ip/ipprefix.c
+++ b/ip/ipprefix.c
@@ -75,15 +75,12 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[PREFIX_ADDRESS]) {
struct in6_addr *pfx;
- char abuf[256];
pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "%s", rt_addr_n2a(family,
RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
- pfx,
- abuf, sizeof(abuf)));
+ pfx));
}
fprintf(fp, "/%u ", prefix->prefix_len);
diff --git a/ip/iproute.c b/ip/iproute.c
index 8315ad3e6c6ac..1ec9294290b2a 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -318,7 +318,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[RTA_MAX+1];
- char abuf[256];
int host_len;
__u32 table;
@@ -373,8 +372,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_dst_len != host_len) {
fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]),
- RTA_DATA(tb[RTA_DST]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[RTA_DST])),
r->rtm_dst_len
);
} else {
@@ -392,8 +390,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_src_len != host_len) {
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
- RTA_DATA(tb[RTA_SRC]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[RTA_SRC])),
r->rtm_src_len
);
} else {
@@ -452,8 +449,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " src %s ",
rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_PREFSRC]),
- RTA_DATA(tb[RTA_PREFSRC]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[RTA_PREFSRC])));
}
if (tb[RTA_PRIORITY])
fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 42abe3753ac6a..53d3ad4e6ea8e 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -70,7 +70,6 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap)
static void print_encap_ip(FILE *fp, struct rtattr *encap)
{
struct rtattr *tb[LWTUNNEL_IP_MAX+1];
- char abuf[256];
parse_rtattr_nested(tb, LWTUNNEL_IP_MAX, encap);
@@ -81,15 +80,13 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)
fprintf(fp, "src %s ",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
- RTA_DATA(tb[LWTUNNEL_IP_SRC]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[LWTUNNEL_IP_SRC])));
if (tb[LWTUNNEL_IP_DST])
fprintf(fp, "dst %s ",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
- RTA_DATA(tb[LWTUNNEL_IP_DST]),
- abuf, sizeof(abuf)));
+ RTA_DATA(tb[LWTUNNEL_IP_DST])));
if (tb[LWTUNNEL_IP_TTL])
fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
diff --git a/ip/iprule.c b/ip/iprule.c
index 345b3b042307d..3fd510efe5e1b 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -57,8 +57,6 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
int host_len = -1;
__u32 table;
struct rtattr *tb[FRA_MAX+1];
- char abuf[256];
-
SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
@@ -87,8 +85,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_src_len != host_len) {
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[FRA_SRC]),
- RTA_DATA(tb[FRA_SRC]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[FRA_SRC])),
r->rtm_src_len
);
} else {
@@ -107,8 +104,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (r->rtm_dst_len != host_len) {
fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[FRA_DST]),
- RTA_DATA(tb[FRA_DST]),
- abuf, sizeof(abuf)),
+ RTA_DATA(tb[FRA_DST])),
r->rtm_dst_len
);
} else {
diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index bfee99561615a..e3161d81beded 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -309,7 +309,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
p->name,
tnl_strproto(p->iph.protocol),
p->iph.daddr ? format_host_r(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
- p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
+ p->iph.saddr ? rt_addr_n2a_r(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
struct ip_tunnel_prl prl[16];
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 860414d377b47..8741ff3b302a9 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -285,17 +285,11 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
__u8 mode, __u32 reqid, __u16 family, int force_spi,
FILE *fp, const char *prefix, const char *title)
{
- char abuf[256];
-
if (title)
fputs(title, fp);
- memset(abuf, '\0', sizeof(abuf));
- fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
- saddr, abuf, sizeof(abuf)));
- memset(abuf, '\0', sizeof(abuf));
- fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr),
- &id->daddr, abuf, sizeof(abuf)));
+ fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr), saddr));
+ fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr), &id->daddr));
fprintf(fp, "%s", _SL_);
if (prefix)
@@ -447,7 +441,6 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
FILE *fp, const char *prefix)
{
- char abuf[256];
__u16 f;
f = sel->family;
@@ -459,16 +452,12 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
if (prefix)
fputs(prefix, fp);
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "src %s/%u ",
- rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr,
- abuf, sizeof(abuf)),
+ rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr),
sel->prefixlen_s);
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "dst %s/%u ",
- rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr,
- abuf, sizeof(abuf)),
+ rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr),
sel->prefixlen_d);
if (sel->proto)
@@ -740,7 +729,6 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
if (tb[XFRMA_ENCAP]) {
struct xfrm_encap_tmpl *e;
- char abuf[256];
if (prefix)
fputs(prefix, fp);
@@ -768,10 +756,8 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
fprintf(fp, "sport %u ", ntohs(e->encap_sport));
fprintf(fp, "dport %u ", ntohs(e->encap_dport));
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "addr %s",
- rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa,
- abuf, sizeof(abuf)));
+ rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa));
fprintf(fp, "%s", _SL_);
}
@@ -783,7 +769,6 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
}
if (tb[XFRMA_COADDR]) {
- char abuf[256];
xfrm_address_t *coa;
if (prefix)
@@ -798,10 +783,8 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
return;
}
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "%s",
- rt_addr_n2a(family, sizeof(*coa), coa,
- abuf, sizeof(abuf)));
+ rt_addr_n2a(family, sizeof(*coa), coa));
fprintf(fp, "%s", _SL_);
}
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index ab5e50a205983..4b32fe5aa8088 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -260,7 +260,6 @@ get_failed:
static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[256];
char s2[64];
int flags = 0;
__u32 flowinfo = 0;
@@ -292,16 +291,14 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
fprintf(f, "remote %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
- RTA_DATA(tb[IFLA_IPTUN_REMOTE]),
- s1, sizeof(s1)));
+ RTA_DATA(tb[IFLA_IPTUN_REMOTE])));
}
if (tb[IFLA_IPTUN_LOCAL]) {
fprintf(f, "local %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
- RTA_DATA(tb[IFLA_IPTUN_LOCAL]),
- s1, sizeof(s1)));
+ RTA_DATA(tb[IFLA_IPTUN_LOCAL])));
}
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
diff --git a/ip/xfrm_monitor.c b/ip/xfrm_monitor.c
index 96b52a44b8a85..9d01a2aab5018 100644
--- a/ip/xfrm_monitor.c
+++ b/ip/xfrm_monitor.c
@@ -227,12 +227,8 @@ static void xfrm_ae_flags_print(__u32 flags, void *arg)
static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp)
{
- char buf[256];
-
- buf[0] = 0;
fprintf(fp, "dst %s ",
- rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr,
- buf, sizeof(buf)));
+ rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr));
fprintf(fp, " reqid 0x%x", reqid);
@@ -245,15 +241,12 @@ static int xfrm_ae_print(const struct sockaddr_nl *who,
{
FILE *fp = (FILE *)arg;
struct xfrm_aevent_id *id = NLMSG_DATA(n);
- char abuf[256];
fprintf(fp, "Async event ");
xfrm_ae_flags_print(id->flags, arg);
fprintf(fp, "\n\t");
- memset(abuf, '\0', sizeof(abuf));
fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
- sizeof(id->saddr), &id->saddr,
- abuf, sizeof(abuf)));
+ sizeof(id->saddr), &id->saddr));
xfrm_usersa_print(&id->sa_id, id->reqid, fp);
@@ -265,10 +258,7 @@ static int xfrm_ae_print(const struct sockaddr_nl *who,
static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
{
- char buf[256];
-
- buf[0] = 0;
- fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a, buf, sizeof(buf)));
+ fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a));
}
static int xfrm_mapping_print(const struct sockaddr_nl *who,
diff --git a/lib/utils.c b/lib/utils.c
index 22a5ef8fa8213..9b303a6b096bc 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -702,7 +702,7 @@ int __get_user_hz(void)
return sysconf(_SC_CLK_TCK);
}
-const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen)
+const char *rt_addr_n2a_r(int af, int len, const void *addr, char *buf, int buflen)
{
switch (af) {
case AF_INET:
@@ -725,6 +725,13 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen
}
}
+const char *rt_addr_n2a(int af, int len, const void *addr)
+{
+ static char buf[256];
+
+ return rt_addr_n2a_r(af, len, addr, buf, 256);
+}
+
int read_family(const char *name)
{
int family = AF_UNSPEC;
@@ -832,7 +839,7 @@ const char *format_host_r(int af, int len, const void *addr,
return n;
}
#endif
- return rt_addr_n2a(af, len, addr, buf, buflen);
+ return rt_addr_n2a_r(af, len, addr, buf, buflen);
}
const char *format_host(int af, int len, const void *addr)
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 6139fe08651a4..40f8c595b2eec 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -394,7 +394,6 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
struct rtattr *addr6_attr,
struct rtattr *mask6_attr)
{
- SPRINT_BUF(b1);
struct rtattr *addr_attr;
struct rtattr *mask_attr;
int family;
@@ -418,16 +417,14 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
return;
fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
RTA_PAYLOAD(addr_attr),
- RTA_DATA(addr_attr),
- b1, sizeof(b1)));
+ RTA_DATA(addr_attr)));
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
return;
bits = __mask_bits(RTA_DATA(mask_attr), len);
if (bits < 0)
fprintf(f, "/%s", rt_addr_n2a(family,
RTA_PAYLOAD(mask_attr),
- RTA_DATA(mask_attr),
- b1, sizeof(b1)));
+ RTA_DATA(mask_attr)));
else if (bits < len * 8)
fprintf(f, "/%d", bits);
}
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 0/7] Refactor some internal library functions
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
The following series is a result of reviewing color output support and
some formatting helpers usually used with struct rtattr fields.
Phil Sutter (7):
color: introduce color helpers and COLOR_CLEAR
ipaddress: colorize peer, broadcast and anycast addresses as well
make format_host non-reentrant by default
utils: make rt_addr_n2a() non-reentrant by default
lib/utils: introduce format_host_rta()
lib/utils: introduce rt_addr_n2a_rta()
lib/ll_addr: improve ll_addr_n2a() a bit
bridge/fdb.c | 4 +--
include/color.h | 5 ++-
include/utils.h | 10 ++++--
ip/ip6tunnel.c | 4 +--
ip/ipaddress.c | 87 ++++++++++++++++++---------------------------------
ip/ipaddrlabel.c | 7 ++---
ip/iplink_bond.c | 7 +----
ip/iplink_geneve.c | 5 ++-
ip/iplink_vxlan.c | 13 ++++----
ip/ipmaddr.c | 6 +---
ip/ipmroute.c | 11 ++-----
ip/ipneigh.c | 6 +---
ip/ipprefix.c | 17 ++--------
ip/iproute.c | 68 ++++++++++++----------------------------
ip/iproute_lwtunnel.c | 29 ++++-------------
ip/iprule.c | 39 +++++++----------------
ip/iptoken.c | 11 ++-----
ip/iptunnel.c | 8 ++---
ip/ipxfrm.c | 29 ++++-------------
ip/link_gre.c | 5 ++-
ip/link_gre6.c | 5 ++-
ip/link_ip6tnl.c | 11 ++-----
ip/link_iptnl.c | 7 ++---
ip/link_vti.c | 5 ++-
ip/link_vti6.c | 5 ++-
ip/tcp_metrics.c | 6 ++--
ip/xfrm_monitor.c | 16 ++--------
lib/color.c | 30 +++++++++++++++++-
lib/ll_addr.c | 15 ++-------
lib/utils.c | 20 ++++++++++--
misc/ss.c | 4 +--
tc/f_flower.c | 11 ++-----
tc/m_nat.c | 4 +--
33 files changed, 187 insertions(+), 323 deletions(-)
--
2.7.2
^ permalink raw reply
* [iproute PATCH 2/7] ipaddress: colorize peer, broadcast and anycast addresses as well
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
ip/ipaddress.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 7aab8e781eae8..90d7b1096c3aa 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -862,7 +862,8 @@ int print_linkinfo(const struct sockaddr_nl *who,
fprintf(fp, " peer ");
else
fprintf(fp, " brd ");
- fprintf(fp, "%s", ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
+ color_fprintf(fp, COLOR_MAC, "%s",
+ ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
RTA_PAYLOAD(tb[IFLA_BROADCAST]),
ifi->ifi_type,
b1, sizeof(b1)));
@@ -1062,32 +1063,34 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
RTA_DATA(rta_tb[IFA_LOCAL]),
abuf, sizeof(abuf)));
- if (rta_tb[IFA_ADDRESS] == NULL ||
- memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
- ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
- fprintf(fp, "/%d ", ifa->ifa_prefixlen);
- } else {
- fprintf(fp, " peer %s/%d ",
- format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
- RTA_DATA(rta_tb[IFA_ADDRESS]),
- abuf, sizeof(abuf)),
- ifa->ifa_prefixlen);
+ if (rta_tb[IFA_ADDRESS] &&
+ memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
+ RTA_DATA(rta_tb[IFA_LOCAL]),
+ ifa->ifa_family == AF_INET ? 4 : 16)) {
+ fprintf(fp, " peer ");
+ color_fprintf(fp, ifa_family_color(ifa->ifa_family),
+ "%s", format_host(ifa->ifa_family,
+ RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
+ RTA_DATA(rta_tb[IFA_ADDRESS]),
+ abuf, sizeof(abuf)));
}
+ fprintf(fp, "/%d ", ifa->ifa_prefixlen);
}
if (brief)
goto brief_exit;
if (rta_tb[IFA_BROADCAST]) {
- fprintf(fp, "brd %s ",
+ fprintf(fp, "brd ");
+ color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
RTA_DATA(rta_tb[IFA_BROADCAST]),
abuf, sizeof(abuf)));
}
if (rta_tb[IFA_ANYCAST]) {
- fprintf(fp, "any %s ",
+ fprintf(fp, "any ");
+ color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
RTA_DATA(rta_tb[IFA_ANYCAST]),
--
2.7.2
^ permalink raw reply related
* [iproute PATCH 1/7] color: introduce color helpers and COLOR_CLEAR
From: Phil Sutter @ 2016-03-22 18:35 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
In-Reply-To: <1458671719-14361-1-git-send-email-phil@nwl.cc>
This adds two helper functions which map a given data field to a color,
so color_fprintf() statements don't have to be duplicated with only a
different color value depending on that data field's value. In order for
this to work in a generic way, COLOR_CLEAR has been added to serve as a
fallback default of uncolored output.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/color.h | 5 ++++-
ip/ipaddress.c | 47 +++++++++++++----------------------------------
lib/color.c | 30 +++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/include/color.h b/include/color.h
index b85003aed19f8..c1c29831159af 100644
--- a/include/color.h
+++ b/include/color.h
@@ -7,10 +7,13 @@ enum color_attr {
COLOR_INET,
COLOR_INET6,
COLOR_OPERSTATE_UP,
- COLOR_OPERSTATE_DOWN
+ COLOR_OPERSTATE_DOWN,
+ COLOR_CLEAR
};
void enable_color(void);
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
+enum color_attr ifa_family_color(__u8 ifa_family);
+enum color_attr oper_state_color(__u8 state);
#endif
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index f8c5029400949..7aab8e781eae8 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -135,25 +135,15 @@ static const char *oper_states[] = {
static void print_operstate(FILE *f, __u8 state)
{
- if (state >= ARRAY_SIZE(oper_states))
+ if (state >= ARRAY_SIZE(oper_states)) {
fprintf(f, "state %#x ", state);
- else {
- if (brief) {
- if (strcmp(oper_states[state], "UP") == 0)
- color_fprintf(f, COLOR_OPERSTATE_UP, "%-14s ", oper_states[state]);
- else if (strcmp(oper_states[state], "DOWN") == 0)
- color_fprintf(f, COLOR_OPERSTATE_DOWN, "%-14s ", oper_states[state]);
- else
- fprintf(f, "%-14s ", oper_states[state]);
- } else {
- fprintf(f, "state ");
- if (strcmp(oper_states[state], "UP") == 0)
- color_fprintf(f, COLOR_OPERSTATE_UP, "%s ", oper_states[state]);
- else if (strcmp(oper_states[state], "DOWN") == 0)
- color_fprintf(f, COLOR_OPERSTATE_DOWN, "%s ", oper_states[state]);
- else
- fprintf(f, "%s ", oper_states[state]);
- }
+ } else if (brief) {
+ color_fprintf(f, oper_state_color(state),
+ "%-14s ", oper_states[state]);
+ } else {
+ fprintf(f, "state ");
+ color_fprintf(f, oper_state_color(state),
+ "%s ", oper_states[state]);
}
}
@@ -1067,22 +1057,11 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
}
if (rta_tb[IFA_LOCAL]) {
- if (ifa->ifa_family == AF_INET)
- color_fprintf(fp, COLOR_INET, "%s", format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
- RTA_DATA(rta_tb[IFA_LOCAL]),
- abuf, sizeof(abuf)));
- else if (ifa->ifa_family == AF_INET6)
- color_fprintf(fp, COLOR_INET6, "%s", format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
- RTA_DATA(rta_tb[IFA_LOCAL]),
- abuf, sizeof(abuf)));
- else
- fprintf(fp, "%s", format_host(ifa->ifa_family,
- RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
- RTA_DATA(rta_tb[IFA_LOCAL]),
- abuf, sizeof(abuf)));
-
+ color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s",
+ format_host(ifa->ifa_family,
+ RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
+ RTA_DATA(rta_tb[IFA_LOCAL]),
+ abuf, sizeof(abuf)));
if (rta_tb[IFA_ADDRESS] == NULL ||
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
diff --git a/lib/color.c b/lib/color.c
index 8c9a48ba702bf..95596be236a05 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -1,5 +1,8 @@
#include <stdio.h>
#include <stdarg.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <linux/if.h>
#include "color.h"
@@ -32,7 +35,8 @@ static enum color attr_colors[] = {
C_MAGENTA,
C_BLUE,
C_GREEN,
- C_RED
+ C_RED,
+ C_CLEAR
};
static int color_is_enabled;
@@ -62,3 +66,27 @@ end:
va_end(args);
return ret;
}
+
+enum color_attr ifa_family_color(__u8 ifa_family)
+{
+ switch (ifa_family) {
+ case AF_INET:
+ return COLOR_INET;
+ case AF_INET6:
+ return COLOR_INET6;
+ default:
+ return COLOR_CLEAR;
+ }
+}
+
+enum color_attr oper_state_color(__u8 state)
+{
+ switch (state) {
+ case IF_OPER_UP:
+ return COLOR_OPERSTATE_UP;
+ case IF_OPER_DOWN:
+ return COLOR_OPERSTATE_DOWN;
+ default:
+ return COLOR_CLEAR;
+ }
+}
--
2.7.2
^ permalink raw reply related
* Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: Lance Richardson @ 2016-03-22 18:41 UTC (permalink / raw)
To: David Ahern; +Cc: netdev
In-Reply-To: <56F18EEE.4070000@cumulusnetworks.com>
----- Original Message -----
> From: "David Ahern" <dsa@cumulusnetworks.com>
> To: "Lance Richardson" <lrichard@redhat.com>, netdev@vger.kernel.org
> Sent: Tuesday, March 22, 2016 2:29:02 PM
> Subject: Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
>
> On 3/22/16 9:31 AM, Lance Richardson wrote:
> > Field fl4.flowi4_flags is not initialized in fib_compute_spec_dst()
> > before calling fib_lookup(), which means fib_table_lookup() is
> > using non-deterministic data at this line:
> >
> > if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
> >
> > Fix by initializing fl4.flowi4_flags to zero.
> >
> > Signed-off-by: Lance Richardson <lrichard@redhat.com>
> > ---
> > net/ipv4/fib_frontend.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> > index 21add55..896844a 100644
> > --- a/net/ipv4/fib_frontend.c
> > +++ b/net/ipv4/fib_frontend.c
> > @@ -304,6 +304,7 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
> > fl4.flowi4_scope = scope;
> > fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
> > fl4.flowi4_tun_key.tun_id = 0;
> > + fl4.flowi4_flags = 0;
> > if (!fib_lookup(net, &fl4, &res, 0))
> > return FIB_RES_PREFSRC(net, res);
> > } else {
> >
>
> Fixes: 58189ca7b2741 ("net: Fix vti use case with oif in dst lookups")
>
> I think a more robust solution is to move fl4 to this if case and init
> when it is declared:
>
> struct flowi4 fl4 = {
> .flowi4_iif = LOOPBACK_IFINDEX,
> .daddr = ip_hdr(skb)->saddr,
> .flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
> .flowi4_scope = scope,
> .flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0,
> };
>
Agreed... I actually debated doing something similar but opted for the
smaller delta.
v2 coming up.
Thanks for the review,
Lance
^ permalink raw reply
* Re: [PATCH v4 2/3] IB/hns: Add HiSilicon RoCE driver support
From: Christoph Hellwig @ 2016-03-22 18:54 UTC (permalink / raw)
To: Lijun Ou
Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w,
davem-fT/PcQaiUtIeIZ0/mPfg9Q,
jeffrey.t.kirsher-ral2JQCrhuEAvxtiuMwx3w,
jiri-VPRAkNaXOzVWk0Htik3J/w, ogerlitz-VPRAkNaXOzVWk0Htik3J/w,
linux-rdma-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
netdev-u79uwXL29TY76Z2rM5mHXA,
gongyangming-hv44wF8Li93QT0dZR+AlfA,
xiaokun-hv44wF8Li93QT0dZR+AlfA,
tangchaofei-hv44wF8Li93QT0dZR+AlfA,
haifeng.wei-hv44wF8Li93QT0dZR+AlfA,
yisen.zhuang-hv44wF8Li93QT0dZR+AlfA,
yankejian-hv44wF8Li93QT0dZR+AlfA,
lisheng011-hv44wF8Li93QT0dZR+AlfA,
charles.chenxin-hv44wF8Li93QT0dZR+AlfA,
linuxarm-hv44wF8Li93QT0dZR+AlfA
In-Reply-To: <1458655621-3618-3-git-send-email-oulijun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> drivers/infiniband/Kconfig | 1 +
> drivers/infiniband/hw/Makefile | 1 +
> drivers/infiniband/hw/hisilicon/hns/Kconfig | 10 +
To fit in with the other drivers drop the hisilicon level
of the directory hierarchy.
Haven't had time to look at the actual driver yet so far, though.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: Lance Richardson @ 2016-03-22 18:56 UTC (permalink / raw)
To: netdev; +Cc: dsa
Field fl4.flowi4_flags is not initialized in fib_compute_spec_dst()
before calling fib_lookup(), which means fib_table_lookup() is
using non-deterministic data at this line:
if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
Fix by initializing the entire fl4 structure, which will prevent
similar issues as fields are added in the future by ensuring that
all fields are initialized to zero unless explicitly initialized
to another value.
Fixes: 58189ca7b2741 ("net: Fix vti use case with oif in dst lookups")
Suggested-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: Lance Richardson <lrichard@redhat.com>
---
net/ipv4/fib_frontend.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 21add55..8a9246d 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -280,7 +280,6 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
struct in_device *in_dev;
struct fib_result res;
struct rtable *rt;
- struct flowi4 fl4;
struct net *net;
int scope;
@@ -296,14 +295,13 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
scope = RT_SCOPE_UNIVERSE;
if (!ipv4_is_zeronet(ip_hdr(skb)->saddr)) {
- fl4.flowi4_oif = 0;
- fl4.flowi4_iif = LOOPBACK_IFINDEX;
- fl4.daddr = ip_hdr(skb)->saddr;
- fl4.saddr = 0;
- fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
- fl4.flowi4_scope = scope;
- fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
- fl4.flowi4_tun_key.tun_id = 0;
+ struct flowi4 fl4 = {
+ .flowi4_iif = LOOPBACK_IFINDEX,
+ .daddr = ip_hdr(skb)->saddr,
+ .flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
+ .flowi4_scope = scope,
+ .flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0,
+ };
if (!fib_lookup(net, &fl4, &res, 0))
return FIB_RES_PREFSRC(net, res);
} else {
--
2.5.5
^ permalink raw reply related
* Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: Lance Richardson @ 2016-03-22 18:58 UTC (permalink / raw)
To: netdev; +Cc: dsa
In-Reply-To: <1458673017-3528-1-git-send-email-lrichard@redhat.com>
Apologies, that should have been [PATCH v2 net].
----- Original Message -----
> From: "Lance Richardson" <lrichard@redhat.com>
> To: netdev@vger.kernel.org
> Cc: dsa@cumulusnetworks.com
> Sent: Tuesday, March 22, 2016 2:56:57 PM
> Subject: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
>
> Field fl4.flowi4_flags is not initialized in fib_compute_spec_dst()
> before calling fib_lookup(), which means fib_table_lookup() is
> using non-deterministic data at this line:
>
> if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
>
> Fix by initializing the entire fl4 structure, which will prevent
> similar issues as fields are added in the future by ensuring that
> all fields are initialized to zero unless explicitly initialized
> to another value.
>
> Fixes: 58189ca7b2741 ("net: Fix vti use case with oif in dst lookups")
> Suggested-by: David Ahern <dsa@cumulusnetworks.com>
> Signed-off-by: Lance Richardson <lrichard@redhat.com>
> ---
> net/ipv4/fib_frontend.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> index 21add55..8a9246d 100644
> --- a/net/ipv4/fib_frontend.c
> +++ b/net/ipv4/fib_frontend.c
> @@ -280,7 +280,6 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
> struct in_device *in_dev;
> struct fib_result res;
> struct rtable *rt;
> - struct flowi4 fl4;
> struct net *net;
> int scope;
>
> @@ -296,14 +295,13 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
>
> scope = RT_SCOPE_UNIVERSE;
> if (!ipv4_is_zeronet(ip_hdr(skb)->saddr)) {
> - fl4.flowi4_oif = 0;
> - fl4.flowi4_iif = LOOPBACK_IFINDEX;
> - fl4.daddr = ip_hdr(skb)->saddr;
> - fl4.saddr = 0;
> - fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
> - fl4.flowi4_scope = scope;
> - fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
> - fl4.flowi4_tun_key.tun_id = 0;
> + struct flowi4 fl4 = {
> + .flowi4_iif = LOOPBACK_IFINDEX,
> + .daddr = ip_hdr(skb)->saddr,
> + .flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
> + .flowi4_scope = scope,
> + .flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0,
> + };
> if (!fib_lookup(net, &fl4, &res, 0))
> return FIB_RES_PREFSRC(net, res);
> } else {
> --
> 2.5.5
>
>
^ permalink raw reply
* Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: David Ahern @ 2016-03-22 19:00 UTC (permalink / raw)
To: Lance Richardson, netdev
In-Reply-To: <1458673017-3528-1-git-send-email-lrichard@redhat.com>
On 3/22/16 12:56 PM, Lance Richardson wrote:
> Field fl4.flowi4_flags is not initialized in fib_compute_spec_dst()
> before calling fib_lookup(), which means fib_table_lookup() is
> using non-deterministic data at this line:
>
> if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
>
> Fix by initializing the entire fl4 structure, which will prevent
> similar issues as fields are added in the future by ensuring that
> all fields are initialized to zero unless explicitly initialized
> to another value.
>
> Fixes: 58189ca7b2741 ("net: Fix vti use case with oif in dst lookups")
> Suggested-by: David Ahern <dsa@cumulusnetworks.com>
> Signed-off-by: Lance Richardson <lrichard@redhat.com>
> ---
> net/ipv4/fib_frontend.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
> index 21add55..8a9246d 100644
> --- a/net/ipv4/fib_frontend.c
> +++ b/net/ipv4/fib_frontend.c
> @@ -280,7 +280,6 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
> struct in_device *in_dev;
> struct fib_result res;
> struct rtable *rt;
> - struct flowi4 fl4;
> struct net *net;
> int scope;
>
> @@ -296,14 +295,13 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
>
> scope = RT_SCOPE_UNIVERSE;
> if (!ipv4_is_zeronet(ip_hdr(skb)->saddr)) {
> - fl4.flowi4_oif = 0;
> - fl4.flowi4_iif = LOOPBACK_IFINDEX;
> - fl4.daddr = ip_hdr(skb)->saddr;
> - fl4.saddr = 0;
> - fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
> - fl4.flowi4_scope = scope;
> - fl4.flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0;
> - fl4.flowi4_tun_key.tun_id = 0;
> + struct flowi4 fl4 = {
> + .flowi4_iif = LOOPBACK_IFINDEX,
> + .daddr = ip_hdr(skb)->saddr,
> + .flowi4_tos = RT_TOS(ip_hdr(skb)->tos),
> + .flowi4_scope = scope,
> + .flowi4_mark = IN_DEV_SRC_VMARK(in_dev) ? skb->mark : 0,
> + };
> if (!fib_lookup(net, &fl4, &res, 0))
> return FIB_RES_PREFSRC(net, res);
> } else {
>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
DaveM: this should go into stable releases back to v4.3.
^ permalink raw reply
* [PATCH net-next] net: Fix remote checksum offload with GUE
From: Tom Herbert @ 2016-03-22 19:19 UTC (permalink / raw)
To: davem, netdev; +Cc: kernel-team, aduyck
In skb_segment the check of whether or not to perform the checksum on
host was changed to not consider rather remote checksum offload is
in use. In the case that can_checksum_protocol fails the checksum
is computed regardless. __skb_udp_tunnel_segment was modified in a
related patch to add NETIF_F_HW_CSUM into features when grabbing
the enc_features and remote checksum offload is being done. The
problem is that this bit can be cleared in lower GSO layers that
are also doing tunneling (e.g. ipip, GRE when used with GUE),
so when we get to skb_segment that intent has been lost and
can_checksum_protocol fails.
This patch:
- Restores the check in skb_segment to look at remote checksum offload.
- Removes the code in __skb_udp_tunnel_segment to force the
NETIF_F_HW_CSUM feature since this is no longer useful with above
change.
- Removes check for remote checksum offload in gso_reset_checksum.
A special case should not be needed here.
Tested: Single netperf STREAM over GUE-ipip
Before fix:
5625 Mbps
After fix:
6410 Mbps
Fixes: 76443456227097179c1482 ("net: Move GSO csum into SKB_GSO_CB")
Signed-off-by: Tom Herbert <tom@herbertland.com>
---
include/linux/skbuff.h | 4 ----
net/core/skbuff.c | 5 ++---
net/ipv4/udp_offload.c | 10 ----------
3 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 15d0df9..f6fe8a5 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3615,10 +3615,6 @@ static inline int gso_pskb_expand_head(struct sk_buff *skb, int extra)
static inline void gso_reset_checksum(struct sk_buff *skb, __wsum res)
{
- /* Do not update partial checksums if remote checksum is enabled. */
- if (skb->remcsum_offload)
- return;
-
SKB_GSO_CB(skb)->csum = res;
SKB_GSO_CB(skb)->csum_start = skb_checksum_start(skb) - skb->head;
}
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f044f97..e4eb78d 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3259,14 +3259,13 @@ skip_fraglist:
nskb->truesize += nskb->data_len;
perform_csum_check:
- if (!csum) {
+ if (!csum && !nskb->remcsum_offload) {
if (skb_has_shared_frag(nskb)) {
err = __skb_linearize(nskb);
if (err)
goto err;
}
- if (!nskb->remcsum_offload)
- nskb->ip_summed = CHECKSUM_NONE;
+ nskb->ip_summed = CHECKSUM_NONE;
SKB_GSO_CB(nskb)->csum =
skb_checksum(nskb, doffset,
nskb->len - doffset, 0);
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 8a3405a..f86f1e1 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -78,16 +78,6 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
features &= skb->dev->hw_enc_features;
- /* The only checksum offload we care about from here on out is the
- * outer one so strip the existing checksum feature flags and
- * instead set the flag based on our outer checksum offload value.
- */
- if (remcsum || ufo) {
- features &= ~NETIF_F_CSUM_MASK;
- if (!need_csum || offload_csum)
- features |= NETIF_F_HW_CSUM;
- }
-
/* segment inner packet. */
segs = gso_inner_segment(skb, features);
if (IS_ERR_OR_NULL(segs)) {
--
2.8.0.rc2
^ permalink raw reply related
* [PATCH] macb: fix PHY reset
From: Sergei Shtylyov @ 2016-03-22 19:27 UTC (permalink / raw)
To: netdev, nicolas.ferre
The driver calls gpiod_set_value() with GPIOD_OUT_* instead of 0 and 1, as
a result the PHY isn't really put back into reset state in macb_remove().
Moreover, the driver assumes that something else has set the GPIO direction
to output, so if it has not, the PHY wouldn't be taken out of reset in
macb_probe() either...
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
---
The patch is against David Miller's 'net.git' repo.
drivers/net/ethernet/cadence/macb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Index: net/drivers/net/ethernet/cadence/macb.c
===================================================================
--- net.orig/drivers/net/ethernet/cadence/macb.c
+++ net/drivers/net/ethernet/cadence/macb.c
@@ -2959,7 +2959,7 @@ static int macb_probe(struct platform_de
int gpio = of_get_named_gpio(phy_node, "reset-gpios", 0);
if (gpio_is_valid(gpio))
bp->reset_gpio = gpio_to_desc(gpio);
- gpiod_set_value(bp->reset_gpio, GPIOD_OUT_HIGH);
+ gpiod_direction_output(bp->reset_gpio, 1);
}
of_node_put(phy_node);
@@ -3029,7 +3029,7 @@ static int macb_remove(struct platform_d
mdiobus_free(bp->mii_bus);
/* Shutdown the PHY if there is a GPIO reset */
- gpiod_set_value(bp->reset_gpio, GPIOD_OUT_LOW);
+ gpiod_set_value(bp->reset_gpio, 0);
unregister_netdev(dev);
clk_disable_unprepare(bp->tx_clk);
^ permalink raw reply
* Re: [PATCH] macb: fix PHY reset
From: Sergei Shtylyov @ 2016-03-22 19:34 UTC (permalink / raw)
To: netdev, nicolas.ferre
In-Reply-To: <3349780.3Prc3uV314@wasted.cogentembedded.com>
On 03/22/2016 10:27 PM, Sergei Shtylyov wrote:
> The driver calls gpiod_set_value() with GPIOD_OUT_* instead of 0 and 1, as
> a result the PHY isn't really put back into reset state in macb_remove().
> Moreover, the driver assumes that something else has set the GPIO direction
> to output, so if it has not, the PHY wouldn't be taken out of reset in
s/wouldn't/may not/, sorry. Do I need to resend?
> macb_probe() either...
>
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
MBR, Sergei
^ permalink raw reply
* Re: [PATCH] net: phy: at803x: don't depend on GPIOLIB
From: Uwe Kleine-König @ 2016-03-22 19:42 UTC (permalink / raw)
To: Sebastian Frias
Cc: Daniel Mack, David S. Miller, netdev, lkml, mason,
Florian Fainelli, Mans Rullgard, Fabio Estevam,
Martin Blumenstingl, Linus Walleij
In-Reply-To: <56F157EF.5080307@laposte.net>
Hello Sebastian,
On Tue, Mar 22, 2016 at 03:34:23PM +0100, Sebastian Frias wrote:
> I think we are in a deadlock :-)
> I'm going to reply inline below, but I will also send a different email
> to Daniel with a small recap.
> I think he should share the intent of the "reset" mechanism he
> introduced, in particular if it is mandatory.
The things I said in my mail are valid in general, not only for the
at803x phy.
Let me repeat them once more:
Preconditions:
- Some of the devices a given driver handles have a reset line and
others don't.
- A non-empty subset (maybe all) of the devices that have a reset line
require that this reset line is used.
Then the way to handle this in the driver should be done as follows:
unless reset_handling_not_necessary():
gpio = gpiod_get_optional("reset")
if IS_ERR(gpio):
return PTR_ERR(gpio)
Checking for -ENOSYS or GPIOLIB=n is not allowed because the device
you're currently handling might need the GPIO, so you must not continue
without the ability to control the line.
So the options you have (as you have a phy that doesn't need the reset
handling):
- enable GPIOLIB (either in your .config or introduce a Kconfig
dependency)
- improve reset_handling_not_necessary() to return true for your case
There is nothing else.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply
* Re: [RFC PATCH 7/9] GSO: Support partial segmentation offload
From: Edward Cree @ 2016-03-22 19:40 UTC (permalink / raw)
To: Alexander Duyck; +Cc: Alexander Duyck, Netdev, David Miller, Tom Herbert
In-Reply-To: <CAKgT0Ud9uPG+9AdT47Q1VygLBnjygyY29sRf=y4Pqe=f2e+bkw@mail.gmail.com>
On 22/03/16 17:47, Alexander Duyck wrote:
> On Tue, Mar 22, 2016 at 10:00 AM, Edward Cree <ecree@solarflare.com> wrote:
>> On 18/03/16 23:25, Alexander Duyck wrote:
>>> This patch adds support for something I am referring to as GSO partial.
>>> The basic idea is that we can support a broader range of devices for
>>> segmentation if we use fixed outer headers and have the hardware only
>>> really deal with segmenting the inner header. The idea behind the naming
>>> is due to the fact that everything before csum_start will be fixed headers,
>>> and everything after will be the region that is handled by hardware.
>>>
>>> With the current implementation it allows us to add support for the
>>> following GSO types with an inner TSO or TSO6 offload:
>>> NETIF_F_GSO_GRE
>>> NETIF_F_GSO_GRE_CSUM
>>> NETIF_F_UDP_TUNNEL
>>> NETIF_F_UDP_TUNNEL_CSUM
>>>
>>> Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
>>> ---
>> If I'm correctly understanding what you're doing, you're building a large
>> TCP segment, feeding it through the encapsulation drivers as normal, then
>> at GSO time you're fixing up length fields, checksums etc. in the headers.
>> I think we can do this more simply, by making it so that at the time when
>> we _generate_ the TCP segment, we give it headers saying it's one MSS big,
>> but have several MSS of data. Similarly when adding the encap headers,
>> they all need to get their lengths from what the layer below tells them,
>> rather than the current length of data in the SKB. Then at GSO time all
>> the headers already have the right things in, and you don't need to call
>> any per-protocol GSO callbacks for them.
> One issue I have to deal with here is that we have no way of knowing
> what the underlying hardware can support at the time of segment being
> created. You have to keep in mind that what we have access to is the
> tunnel dev in many cases, not the underlying dev so we don't know if
> things can be offloaded to hardware or not. By pushing this logic
> into the GSO code we can actually implement it without much overhead
> since we either segment it into an MSS multiple, or into single MSS
> sized chunks. This way we defer the decision until the very last
> moment when we actually know if we can offload some portion of this in
> hardware or not.
But won't the tunnel dev have the feature flag for GSO_PARTIAL depending
on what the underlying dev advertises? (Or, at least, could we make it
bethatway?)
Alternatively, have per-protocol GSO callbacks to do the fixup in the
opposite direction to what you have now - in the long term we hope that
hardware supporting GSO partial will become the common case, so that
should be the fast path without bouncing backwards through GSO callbacks.
Then, if you find out at GSO time that the hardware wants to do old-style
TSO, you call those callbacks so as to give it a superframe with the long
lengths filled in everywhere. (Even that might not be necessary; it's a
question of whether hardware makes assumptions about what those fields
contain when folding its packet edits into checksums. Since this is
going to be driver-specific and drivers doing these things will have a
fixed list of what encaps they can parse and therefore do this for, maybe
all these fixups could be done by the driver - using common helper
functions, of course - in its TSO path.)
>> Any protocol that noticed it was putting something non-copyable in its
>> headers (e.g. GRE with the Counter field, or an outer IP layer without DF
>> set needing real IPIDs) would set a flag in the SKB to indicate that we
>> really do need to call through the per-protocol GSO stuff. (Ideally, if
>> we had a separate skb->gso_start field rather than piggybacking on
>> csum_start, we could reset it to point just before us, so that any further
>> headers outside us still can be copied rather than taking callbacks. But
>> I'm not sure whether that's worth using up sk_buff real estate for.)
> The idea behind piggybacking on csum_start was due to the fact that we
> cannot perform GSO/TSO unless CHECKSUM_PARTIAL is set. As far as I
> know in the case of TCP offloads this always ends up being the
> inner-most L4 header so it works out in that it actually reduces code
> path as we were having to deal with all the skb->encapsulation checks.
> It was a relationship that already existed, I just decided to make use
> of it since it simplifies things pretty significantly.
Yes; it's a clever idea. Only trouble is that we really want theinner IP
header rather than the inner TCP header, so that we can (if we want to)
increment the inner IP IDs. Of course, if we Officially Don't Care about
inner IP IDs that's not a problem.
Iwonder if we could just always fill in inner_network_headereven if we're
not doing encapsulation. Or does it end up pointing to a 'middle' header
in the case of nested encap?
> As far as retreating I don't really see how that would work. In most
> cases it is an all-or-nothing proposition to setup these outer
> headers. Either we can segment the frame with the outer headers
> replicated or we cannot. I suspect it would end up being a common
> case where the hardware will update the outer IP and inner TCP
> headers, but I think the outer L4 and inner IP headers will be the
> ones that most likely always end up being static.
Having thought a bit more about this, I think supporting anything other
than "hardware updates inner [IP and] TCPheaders" is needlessly complex
(well, we still have to handle "hardware updates everything 'cos it
thinks it knows best", because that already exists in the wild in
hardware that might not support the new way). I don't think there's
likely to be a case where hardware can do half of the segmentation at
the same time as copying headers for the other half.
I also still don't see why hardware would want to update the outer IP
header - can you explain?
> Also we already
> have code paths in place in the GRE driver for instance that prevent
> us from using GSO in the case of TUNNEL_SEQ being enabled.
Oh good, one less thing to worry about.
>> (It might still be necessary to put the true length in the TCP header, if
>> hardware is using that as an input to segmentation. I think sfc hardware
>> just uses 'total length of all payload DMA descriptors', but others might
>> behave differently.)
> That is what most drivers do. The way I kind of retained that is that
> the TCP header doesn't include an actual length field, but I left the
> pseudo-header using the full length of all data.
But then you're guaranteed to have to update the outer L4 checksum when
yousegment (because outer LCO reads the inner pseudo-header checksum).
Why not use the single-segment length in the pseudo-header, then the
outer L4 checksum is already the right thing? (And if yourhardware
can't be told to leave the outer L4 checksum alone, then it's not worth
the trouble of trying to support GSO partial for it, since it clearly
wants to do old-style "NIC knows best" TSO.)
Then if the hardware is assuming the (inner) pseudo is using the full
length, and is going to include that edit in its checksum calculation,
you can just do the opposite edit in the driver, just before handing
the packet off to the hardware.
Again, the idea is that we optimise for GSO partial by making it a plain
header copy everywhere, and put all the 'fix things up' on the _other_
path.
And yes, I forgot (and keep forgetting) that the TCP header doesn't have
an explicit length field.
> My thought was to
> end up using something like the ixgbe approach for most devices. What
> I did there was replicate the tunnel headers and inner IPv4 or IPv6
> header. In the case of ixgbe and i40e I can throw away the checksum
> and length values for the outer IP header, one thing I was curious
> about is if I really needed to retain the full packet size for those.
Again, the outer IP header should be computed for a single segment
rather than for the superframe, so that it doesn't need to be edited
later. It should be possible to send a "GSO partial" frame to TSO
withouta single GSO callback needing to be called; similarly,
software GSO should be able to just copy the outer headers, and only
need to know how to update the TCP header. (See below for my "what
a NIC should do" TSO design, which software can easily emulate.)
>> However, I haven't yet had the time to attempt to implement this, so there
>> might be some obvious reason I'm missing why this is impossible.
>> Also, it's possible that I've completely misunderstood your patch and it's
>> orthogonal to and can coexist with what I'm suggesting.
> The one piece I could really use would be an understanding of what
> inputs your hardware is expecting in order for us to extend TSO to
> support this kind of approach. Then I could start tailoring the
> output generated so that we had something that would work with more
> devices. I was thinking the approach I have taken is fairly generic
> since essentially it allows us to get away with TSO as long as we are
> allowed to provide the offsets for the IP header and the TCP header.
> From what I can tell it looks like the Solarflare drivers do something
> similar so you might even try making changes similar to what I did for
> ixgbe to see if you can get a proof of concept working for sfc.
So, this is all still slightly speculative because while I've talked to
some of our firmware developers, we haven't got as far as actually writing
the new firmware. I'd also like to make clear that this isn't "what
Solarflare has officially decided to do"; rather it's "what I'm currently
trying to convince people at Solarflare to do".
But what I think we're going to end up with is this:
The kernel will give us a packet that looks like a single MSS-sized segment
except that the payload is too long; the length fields in all the headers
are for an MSS-sized segment, and the checksums are correct for that
(except that the inner TCP checksum is, of course, the pseudo-header sum
rather than a sum over the whole payload). The kernel will also tell us
where in the packet the inner IP header begins. The driver will then give
the following descriptors to the hardware:
* A TSO descriptor, containing the offset of the inner IP header, and the
MSS to use for segmentation.
* A DMA descriptor containing all the headers (i.e. up to the end of the
inner TCP header).
* A series of DMA descriptors containing the payload, with a total length
divisible by the MSS we thought of earlier.
The NIC can now read IHL from the inner IP header, and thereby compute the
offset of the inner TCP header, and the csum_start/offset values.
Then for each MSS-sized block of payload, the NIC will do the following:
* transmit header + payload block
* increment inner IP ID, and decrement inner IP checksum (ones-complement)
* add MSS to TCP sequence number
I believe this is something thatany NIC with TSO support should be able to
learn to do, with appropriate firmware changes. It might be a while before
there are NICs in the wild that can do this,though.
-Ed
^ permalink raw reply
* Re: [PATCH 4/5] net: sxgbe: fix error paths in sxgbe_platform_probe()
From: Rasmus Villemoes @ 2016-03-22 19:47 UTC (permalink / raw)
To: Byungho An; +Cc: Girish K S, netdev, linux-kernel
In-Reply-To: <8737s0d7iz.fsf@rasmusvillemoes.dk>
ping^2
On Tue, Mar 08 2016, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> ping
>
> On Tue, Feb 09 2016, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>
>> We need to use post-decrement to ensure that irq_dispose_mapping is
>> also called on priv->rxq[0]->irq_no; moreover, if one of the above for
>> loops failed already at i==0 (so we reach one of these labels with
>> that value of i), we'll enter an essentially infinite loop of
>> out-of-bounds accesses.
>>
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>> ---
>> drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
>> index b02eed12bfc5..73427e29df2a 100644
>> --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
>> +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c
>> @@ -155,11 +155,11 @@ static int sxgbe_platform_probe(struct platform_device *pdev)
>> return 0;
>>
>> err_rx_irq_unmap:
>> - while (--i)
>> + while (i--)
>> irq_dispose_mapping(priv->rxq[i]->irq_no);
>> i = SXGBE_TX_QUEUES;
>> err_tx_irq_unmap:
>> - while (--i)
>> + while (i--)
>> irq_dispose_mapping(priv->txq[i]->irq_no);
>> irq_dispose_mapping(priv->irq);
>> err_drv_remove:
^ permalink raw reply
* Re: [PATCH V2 net 00/10] net: hns: bugs fixed for hns
From: David Miller @ 2016-03-22 19:50 UTC (permalink / raw)
To: Yisen.Zhuang
Cc: yankejian, huangdaode, salil.mehta, lisheng011, lipeng321,
liguozhu, arnd, sergei.shtylyov, xieqianqian, andrew, ivecera,
netdev, linux-kernel, linuxarm
In-Reply-To: <1458633991-64313-1-git-send-email-Yisen.Zhuang@huawei.com>
From: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Date: Tue, 22 Mar 2016 16:06:21 +0800
> This series includes some bug fixes and updates for hns driver.
>
>>from Daode, one fix about mss.
>
>>from Kejian, one fix about ping6 issue, one fix about mac address setting,
> two fix for RSS setting, two fix about mtu setting.
>
>>from qianqian, fixed HNS v2 xge statistic reg issue.
>
>>from Sheng, one fix about manage packets sending, one fix about GMACs mac
> setting.
>
> For more details, please see individual patches.
Series applied, thanks.
^ permalink raw reply
* Re: [PATCH net v2] ipv4: fix broadcast packets reception
From: David Miller @ 2016-03-22 19:54 UTC (permalink / raw)
To: pabeni; +Cc: netdev, kuznet, sbohrer, hannes
In-Reply-To: <c8ad97bbb6f1c9ec8c523209c1203d1982faab6f.1458634653.git.pabeni@redhat.com>
From: Paolo Abeni <pabeni@redhat.com>
Date: Tue, 22 Mar 2016 09:19:38 +0100
> Currently, ingress ipv4 broadcast datagrams are dropped since,
> in udp_v4_early_demux(), ip_check_mc_rcu() is invoked even on
> bcast packets.
>
> This patch addresses the issue, invoking ip_check_mc_rcu()
> only for mcast packets.
>
> Fixes: 6e5403093261 ("ipv4/udp: Verify multicast group is ours in upd_v4_early_demux()")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>
> --
> v1 -> v2 droped the route related bits, the fib_validate_source()
> failures are triggered by the in_device configuration
Applied and queued up for -stable, thanks.
^ permalink raw reply
* Re: [PATCH v8 net-next] ravb: Add dma queue interrupt support
From: David Miller @ 2016-03-22 19:55 UTC (permalink / raw)
To: ykaneko0929
Cc: netdev, sergei.shtylyov, horms, magnus.damm, linux-renesas-soc
In-Reply-To: <1458660120-23594-1-git-send-email-ykaneko0929@gmail.com>
From: Yoshihiro Kaneko <ykaneko0929@gmail.com>
Date: Wed, 23 Mar 2016 00:22:00 +0900
> From: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
>
> This patch supports the following interrupts.
>
> - One interrupt for multiple (timestamp, error, gPTP)
> - One interrupt for emac
> - Four interrupts for dma queue (best effort rx/tx, network control rx/tx)
>
> This patch improve efficiency of the interrupt handler by adding the
> interrupt handler corresponding to each interrupt source described
> above. Additionally, it reduces the number of times of the access to
> EthernetAVB IF.
> Also this patch prevent this driver depends on the whim of a boot loader.
>
> [ykaneko0929@gmail.com: define bit names of registers]
> [ykaneko0929@gmail.com: add comment for gen3 only registers]
> [ykaneko0929@gmail.com: fix coding style]
> [ykaneko0929@gmail.com: update changelog]
> [ykaneko0929@gmail.com: gen3: fix initialization of interrupts]
> [ykaneko0929@gmail.com: gen3: fix clearing interrupts]
> [ykaneko0929@gmail.com: gen3: add helper function for request_irq()]
> [ykaneko0929@gmail.com: gen3: remove IRQF_SHARED flag for request_irq()]
> [ykaneko0929@gmail.com: revert ravb_close() and ravb_ptp_stop()]
> [ykaneko0929@gmail.com: avoid calling free_irq() to non-hooked interrupts]
> [ykaneko0929@gmail.com: make NC/BE interrupt handler a function]
> [ykaneko0929@gmail.com: make timestamp interrupt handler a function]
> [ykaneko0929@gmail.com: timestamp interrupt is handled in multiple
> interrupt handler instead of dma queue interrupt handler]
> Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
Sorry, it is not appropriate to submit new features and major optimizations
at this time.
Please wait until some reasonable time after the merge window closes to
resubmit this.
Thanks.
^ permalink raw reply
* Re: [PATCH] fsl/fman: Workaround for Errata A-007273
From: David Miller @ 2016-03-22 19:58 UTC (permalink / raw)
To: igal.liberman; +Cc: netdev, scottwood, madalin.bucur
In-Reply-To: <1458594492-15529-1-git-send-email-igal.liberman@freescale.com>
From: <igal.liberman@freescale.com>
Date: Mon, 21 Mar 2016 23:08:11 +0200
> From: Igal Liberman <igal.liberman@freescale.com>
>
> Errata A-007273 (For FMan V3 devices only):
> FMan soft reset is not finished properly if one
> of the Ethernet MAC clocks is disabled
>
> Workaround:
> Re-enable all disabled MAC clocks through the DCFG_CCSR_DEVDISR2
> register prior to issuing an FMAN soft reset.
> Re-disable the MAC clocks after the FMAN soft reset is done.
>
> Signed-off-by: Igal Liberman <igal.liberman@freescale.com>
Applied, thanks.
^ permalink raw reply
* Re: [PATCH net] ipv4: initialize flowi4_flags before calling fib_lookup()
From: David Miller @ 2016-03-22 20:03 UTC (permalink / raw)
To: lrichard; +Cc: netdev, dsa
In-Reply-To: <688989936.72666829.1458673139415.JavaMail.zimbra@redhat.com>
From: Lance Richardson <lrichard@redhat.com>
Date: Tue, 22 Mar 2016 14:58:59 -0400 (EDT)
> Apologies, that should have been [PATCH v2 net].
No worries.
Applied and queued up for -stable, thanks.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox