* [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper
@ 2015-01-06 16:23 Jiri Pirko
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
2015-01-07 23:15 ` [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Stephen Hemminger
0 siblings, 2 replies; 9+ messages in thread
From: Jiri Pirko @ 2015-01-06 16:23 UTC (permalink / raw)
To: netdev; +Cc: stephen, thaller
Sometimes, it is more convenient to get only one specific nested attribute by
type. For example for IFLA_AF_SPEC where type is address family (AF_INET6).
So add this helper for this purpose.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
include/libnetlink.h | 4 ++++
lib/libnetlink.c | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index fe7d5d3..f0faf2d 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -80,11 +80,15 @@ extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int le
extern int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,
int len, unsigned short flags);
extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
+extern struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
extern int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
#define parse_rtattr_nested(tb, max, rta) \
(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
+#define parse_rtattr_one_nested(type, rta) \
+ (parse_rtattr_one(type, RTA_DATA(rta), RTA_PAYLOAD(rta)))
+
#define parse_rtattr_nested_compat(tb, max, rta, data, len) \
({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
__parse_rtattr_nested_compat(tb, max, rta, len); })
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 8d504a9..8e70263 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -701,6 +701,18 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int l
return i;
}
+struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len)
+{
+ while (RTA_OK(rta, len)) {
+ if (rta->rta_type == type)
+ return rta;
+ rta = RTA_NEXT(rta, len);
+ }
+ if (len)
+ fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
+ return NULL;
+}
+
int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta,
int len)
{
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-06 16:23 [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Jiri Pirko
@ 2015-01-06 16:23 ` Jiri Pirko
2015-01-06 16:52 ` Thomas Haller
2015-01-07 23:10 ` Stephen Hemminger
2015-01-07 23:15 ` [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Stephen Hemminger
1 sibling, 2 replies; 9+ messages in thread
From: Jiri Pirko @ 2015-01-06 16:23 UTC (permalink / raw)
To: netdev; +Cc: stephen, thaller
addrgenmode is currently write only by ip. So display this information
if provided by kernel as well.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
ip/ipaddress.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 4d99324..0a04d90 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -242,6 +242,29 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
}
}
+static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
+{
+ struct rtattr *inet6_attr;
+ struct rtattr *tb[IFLA_INET6_MAX + 1];
+
+ inet6_attr = parse_rtattr_one_nested(AF_INET6, af_spec_attr);
+ if (!inet6_attr)
+ return;
+
+ parse_rtattr_nested(tb, IFLA_INET6_MAX, inet6_attr);
+
+ if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
+ switch (rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE])) {
+ case IN6_ADDR_GEN_MODE_EUI64:
+ fprintf(fp, "addrgenmode eui64 ");
+ break;
+ case IN6_ADDR_GEN_MODE_NONE:
+ fprintf(fp, "addrgenmode none ");
+ break;
+ }
+ }
+}
+
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
{
struct ifla_vf_mac *vf_mac;
@@ -634,6 +657,9 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (do_link && tb[IFLA_LINKINFO] && show_details)
print_linktype(fp, tb[IFLA_LINKINFO]);
+ if (do_link && tb[IFLA_AF_SPEC] && show_details)
+ print_af_spec(fp, tb[IFLA_AF_SPEC]);
+
if (do_link && tb[IFLA_IFALIAS]) {
fprintf(fp, "%s alias %s", _SL_,
rta_getattr_str(tb[IFLA_IFALIAS]));
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
@ 2015-01-06 16:52 ` Thomas Haller
2015-01-06 17:08 ` Jiri Pirko
2015-01-07 23:10 ` Stephen Hemminger
1 sibling, 1 reply; 9+ messages in thread
From: Thomas Haller @ 2015-01-06 16:52 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, stephen
[-- Attachment #1: Type: text/plain, Size: 810 bytes --]
On Tue, 2015-01-06 at 17:23 +0100, Jiri Pirko wrote:
> addrgenmode is currently write only by ip. So display this information
> if provided by kernel as well.
>
> +static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
> +{
> + struct rtattr *inet6_attr;
> + struct rtattr *tb[IFLA_INET6_MAX + 1];
> +
> + inet6_attr = parse_rtattr_one_nested(AF_INET6, af_spec_attr);
> + if (!inet6_attr)
> + return;
> +
> + parse_rtattr_nested(tb, IFLA_INET6_MAX, inet6_attr);
> +
> + if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
> + switch (rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE])) {
> + case IN6_ADDR_GEN_MODE_EUI64:
> + fprintf(fp, "addrgenmode eui64 ");
eui64 is the default and the behavior of older kernels.
I dunno, would it be better not to print the default case?
Thomas
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-06 16:52 ` Thomas Haller
@ 2015-01-06 17:08 ` Jiri Pirko
0 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2015-01-06 17:08 UTC (permalink / raw)
To: Thomas Haller; +Cc: netdev, stephen
Tue, Jan 06, 2015 at 05:52:33PM CET, thaller@redhat.com wrote:
>On Tue, 2015-01-06 at 17:23 +0100, Jiri Pirko wrote:
>> addrgenmode is currently write only by ip. So display this information
>> if provided by kernel as well.
>
>>
>> +static void print_af_spec(FILE *fp, struct rtattr *af_spec_attr)
>> +{
>> + struct rtattr *inet6_attr;
>> + struct rtattr *tb[IFLA_INET6_MAX + 1];
>> +
>> + inet6_attr = parse_rtattr_one_nested(AF_INET6, af_spec_attr);
>> + if (!inet6_attr)
>> + return;
>> +
>> + parse_rtattr_nested(tb, IFLA_INET6_MAX, inet6_attr);
>> +
>> + if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
>> + switch (rta_getattr_u8(tb[IFLA_INET6_ADDR_GEN_MODE])) {
>> + case IN6_ADDR_GEN_MODE_EUI64:
>> + fprintf(fp, "addrgenmode eui64 ");
>
>eui64 is the default and the behavior of older kernels.
>
>I dunno, would it be better not to print the default case?
This prints only when show_details is on. So I believe it is ok to print
the default value of addrgenmode (same is done as for other things)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
2015-01-06 16:52 ` Thomas Haller
@ 2015-01-07 23:10 ` Stephen Hemminger
2015-01-08 7:04 ` Jiri Pirko
1 sibling, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2015-01-07 23:10 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, thaller
On Tue, 6 Jan 2015 17:23:46 +0100
Jiri Pirko <jiri@resnulli.us> wrote:
> addrgenmode is currently write only by ip. So display this information
> if provided by kernel as well.
>
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Patch does not apply to current iproute2 git
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-07 23:10 ` Stephen Hemminger
@ 2015-01-08 7:04 ` Jiri Pirko
2015-01-08 7:13 ` Vadim Kochan
2015-01-08 18:19 ` Stephen Hemminger
0 siblings, 2 replies; 9+ messages in thread
From: Jiri Pirko @ 2015-01-08 7:04 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, thaller
Thu, Jan 08, 2015 at 12:10:36AM CET, stephen@networkplumber.org wrote:
>On Tue, 6 Jan 2015 17:23:46 +0100
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> addrgenmode is currently write only by ip. So display this information
>> if provided by kernel as well.
>>
>> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
>
>Patch does not apply to current iproute2 git
I made that against net-next branch. Which branch should I use for new
features?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-08 7:04 ` Jiri Pirko
@ 2015-01-08 7:13 ` Vadim Kochan
2015-01-08 18:19 ` Stephen Hemminger
1 sibling, 0 replies; 9+ messages in thread
From: Vadim Kochan @ 2015-01-08 7:13 UTC (permalink / raw)
To: Jiri Pirko; +Cc: Stephen Hemminger, netdev, thaller
On Thu, Jan 08, 2015 at 08:04:39AM +0100, Jiri Pirko wrote:
> Thu, Jan 08, 2015 at 12:10:36AM CET, stephen@networkplumber.org wrote:
> >On Tue, 6 Jan 2015 17:23:46 +0100
> >Jiri Pirko <jiri@resnulli.us> wrote:
> >
> >> addrgenmode is currently write only by ip. So display this information
> >> if provided by kernel as well.
> >>
> >> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
> >
> >Patch does not apply to current iproute2 git
>
> I made that against net-next branch. Which branch should I use for new
> features?
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
I am not sure if I am right, but seems to me that net-next should keep
features which depends on the next Linux headers version, and as I
understand these new headers are merged into net-next branch and after
into master. But I tried fix your patch on the master and it compiles
OK, so I assume that it can be based on master branch.
Regards,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch iproute2 2/2] iplink: print out addrgenmode attribute
2015-01-08 7:04 ` Jiri Pirko
2015-01-08 7:13 ` Vadim Kochan
@ 2015-01-08 18:19 ` Stephen Hemminger
1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2015-01-08 18:19 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, thaller
On Thu, 8 Jan 2015 08:04:39 +0100
Jiri Pirko <jiri@resnulli.us> wrote:
> Thu, Jan 08, 2015 at 12:10:36AM CET, stephen@networkplumber.org wrote:
> >On Tue, 6 Jan 2015 17:23:46 +0100
> >Jiri Pirko <jiri@resnulli.us> wrote:
> >
> >> addrgenmode is currently write only by ip. So display this information
> >> if provided by kernel as well.
> >>
> >> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
> >
> >Patch does not apply to current iproute2 git
>
> I made that against net-next branch. Which branch should I use for new
> features?
>
net-next hasn't been rebased to master. plus unless change is specific to
kernel net-next it should be against master.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper
2015-01-06 16:23 [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Jiri Pirko
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
@ 2015-01-07 23:15 ` Stephen Hemminger
1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2015-01-07 23:15 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, thaller
On Tue, 6 Jan 2015 17:23:45 +0100
Jiri Pirko <jiri@resnulli.us> wrote:
> Sometimes, it is more convenient to get only one specific nested attribute by
> type. For example for IFLA_AF_SPEC where type is address family (AF_INET6).
> So add this helper for this purpose.
>
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
This one applies.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-01-08 18:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-06 16:23 [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Jiri Pirko
2015-01-06 16:23 ` [patch iproute2 2/2] iplink: print out addrgenmode attribute Jiri Pirko
2015-01-06 16:52 ` Thomas Haller
2015-01-06 17:08 ` Jiri Pirko
2015-01-07 23:10 ` Stephen Hemminger
2015-01-08 7:04 ` Jiri Pirko
2015-01-08 7:13 ` Vadim Kochan
2015-01-08 18:19 ` Stephen Hemminger
2015-01-07 23:15 ` [patch iproute2 1/2] libnetlink: add parse_rtattr_one_nested helper Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.