From 303cc9cbeed6cfb9f08a4073f07cb466cc8098e8 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Thu, 15 Oct 2015 13:13:38 +0200 Subject: [PATCH 1/3] libnetlink: introduce rta_nest and u8, u16, u64 helpers for nesting within rtattr This patch introduces two new api's rta_nest and rta_nest_end to nest attributes inside a rta attribute represented by 'struct rtattr' as required to construct a nexthop. Also adds rta_addattr* variants for u8, u16 and u64 as needed to support encapsulation. Signed-off-by: Roopa Prabhu Signed-off-by: Thomas Graf Acked-by: Jiri Benc --- include/libnetlink.h | 10 ++++++++++ lib/libnetlink.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/libnetlink.h b/include/libnetlink.h index 0503dea5..407440d8 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -86,7 +86,10 @@ int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, const void *data, int len); int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest); +int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data); +int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data); int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); +int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data); int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen); @@ -98,6 +101,13 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len); +struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type); +int rta_nest_end(struct rtattr *rta, struct rtattr *nest); + +#define RTA_TAIL(rta) \ + ((struct rtattr *) (((void *) (rta)) + \ + RTA_ALIGN((rta)->rta_len))) + #define parse_rtattr_nested(tb, max, rta) \ (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 46cac34c..8430033b 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -721,6 +721,37 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type, return 0; } +int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data) +{ + return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u8)); +} + +int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data) +{ + return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u16)); +} + +int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data) +{ + return rta_addattr_l(rta, maxlen, type, &data, sizeof(__u64)); +} + +struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type) +{ + struct rtattr *nest = RTA_TAIL(rta); + + rta_addattr_l(rta, maxlen, type, NULL, 0); + + return nest; +} + +int rta_nest_end(struct rtattr *rta, struct rtattr *nest) +{ + nest->rta_len = (void *)RTA_TAIL(rta) - (void *)nest; + + return rta->rta_len; +} + int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) { return parse_rtattr_flags(tb, max, rta, len, 0); From 39ca4879a09aa0a8d0ba5695657ff18fbae734c6 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Thu, 15 Oct 2015 11:47:43 -0700 Subject: [PATCH 2/3] ip monitor neigh: Change 'delete' to 'Deleted' to be consistent with ip route It helps to grep for one string "Deleted" when monitoring all events. Fixes: 6ea3ebafe077 ("iproute2: inform user when a neighbor is removed") Signed-off-by: Roopa Prabhu Acked-by: Nicolas Dichtel --- ip/ipneigh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/ipneigh.c b/ip/ipneigh.c index a9e23f45..ce57edeb 100644 --- a/ip/ipneigh.c +++ b/ip/ipneigh.c @@ -256,7 +256,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) } if (n->nlmsg_type == RTM_DELNEIGH) - fprintf(fp, "delete "); + fprintf(fp, "Deleted "); else if (n->nlmsg_type == RTM_GETNEIGH) fprintf(fp, "miss "); if (tb[NDA_DST]) { From 6f07f3dc41545657c0364eb17850b946f41861bf Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 16 Oct 2015 12:38:33 +0200 Subject: [PATCH 3/3] ip-address: fix oneline mode for interfaces with VF Signed-off-by: Phil Sutter --- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index e864ca65..f290205b 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -345,7 +345,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) } else vf_linkstate = NULL; - fprintf(fp, "\n vf %d MAC %s", vf_mac->vf, + fprintf(fp, "%s vf %d MAC %s", _SL_, vf_mac->vf, ll_addr_n2a((unsigned char *)&vf_mac->mac, ETH_ALEN, 0, b1, sizeof(b1))); if (vf_vlan->vlan)