All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] genl: ctrl: print op -> policy idx mapping
@ 2020-10-03  8:45 Johannes Berg
  2020-10-12  2:10 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2020-10-03  8:45 UTC (permalink / raw)
  To: netdev; +Cc: Jakub Kicinski, David Ahern

Newer kernels can dump per-op policies, so print out the new
mapping attribute to indicate which op has which policy.

v2:
 * print out both do/dump policy idx
v3:
 * fix userspace API which renumbered after patch rebasing

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
 genl/ctrl.c                    | 27 +++++++++++++++++++++++++++
 include/uapi/linux/genetlink.h | 11 +++++++++++
 2 files changed, 38 insertions(+)

diff --git a/genl/ctrl.c b/genl/ctrl.c
index 68099fe97f1a..549bc6635831 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -162,6 +162,33 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
 		__u32 *ma = RTA_DATA(tb[CTRL_ATTR_MAXATTR]);
 		fprintf(fp, " max attribs: %d ",*ma);
 	}
+	if (tb[CTRL_ATTR_OP_POLICY]) {
+		const struct rtattr *pos;
+
+		rtattr_for_each_nested(pos, tb[CTRL_ATTR_OP_POLICY]) {
+			struct rtattr *ptb[CTRL_ATTR_POLICY_DUMP_MAX + 1];
+			struct rtattr *pattrs = RTA_DATA(pos);
+			int plen = RTA_PAYLOAD(pos);
+
+			parse_rtattr_flags(ptb, CTRL_ATTR_POLICY_DUMP_MAX,
+					   pattrs, plen, NLA_F_NESTED);
+
+			fprintf(fp, " op %d policies:",
+				pos->rta_type & ~NLA_F_NESTED);
+
+			if (ptb[CTRL_ATTR_POLICY_DO]) {
+				__u32 *v = RTA_DATA(ptb[CTRL_ATTR_POLICY_DO]);
+
+				fprintf(fp, " do=%d", *v);
+			}
+
+			if (ptb[CTRL_ATTR_POLICY_DUMP]) {
+				__u32 *v = RTA_DATA(ptb[CTRL_ATTR_POLICY_DUMP]);
+
+				fprintf(fp, " dump=%d", *v);
+			}
+		}
+	}
 	if (tb[CTRL_ATTR_POLICY])
 		nl_print_policy(tb[CTRL_ATTR_POLICY], fp);
 
diff --git a/include/uapi/linux/genetlink.h b/include/uapi/linux/genetlink.h
index 7c6c390c48ee..9fa720ee87ae 100644
--- a/include/uapi/linux/genetlink.h
+++ b/include/uapi/linux/genetlink.h
@@ -64,6 +64,8 @@ enum {
 	CTRL_ATTR_OPS,
 	CTRL_ATTR_MCAST_GROUPS,
 	CTRL_ATTR_POLICY,
+	CTRL_ATTR_OP_POLICY,
+	CTRL_ATTR_OP,
 	__CTRL_ATTR_MAX,
 };
 
@@ -85,6 +87,15 @@ enum {
 	__CTRL_ATTR_MCAST_GRP_MAX,
 };
 
+enum {
+	CTRL_ATTR_POLICY_UNSPEC,
+	CTRL_ATTR_POLICY_DO,
+	CTRL_ATTR_POLICY_DUMP,
+
+	__CTRL_ATTR_POLICY_DUMP_MAX,
+	CTRL_ATTR_POLICY_DUMP_MAX = __CTRL_ATTR_POLICY_DUMP_MAX - 1
+};
+
 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
 
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] genl: ctrl: print op -> policy idx mapping
  2020-10-03  8:45 [PATCH v3] genl: ctrl: print op -> policy idx mapping Johannes Berg
@ 2020-10-12  2:10 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2020-10-12  2:10 UTC (permalink / raw)
  To: Johannes Berg, netdev; +Cc: Jakub Kicinski

On 10/3/20 1:45 AM, Johannes Berg wrote:
> Newer kernels can dump per-op policies, so print out the new
> mapping attribute to indicate which op has which policy.
> 
> v2:
>  * print out both do/dump policy idx
> v3:
>  * fix userspace API which renumbered after patch rebasing
> 

applied to iproute2-next.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-12  2:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-03  8:45 [PATCH v3] genl: ctrl: print op -> policy idx mapping Johannes Berg
2020-10-12  2:10 ` David Ahern

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.