From a62eac97f954c6e025fb1d45e7c289d14aca2305 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Wed, 29 Jun 2016 23:13:58 +0200 Subject: libnl-tiny: Generic Netlink multicast groups support This adds this commit from normal libnl to libnl-tiny: https://github.com/tgraf/libnl/commit/2dbc1ca76c5b82c40749e609eb83877418abb006 commit 2dbc1ca76c5b82c40749e609eb83877418abb006 Author: dima Date: Wed Oct 13 17:53:34 2010 +0300 Generic Netlink multicast groups support I have a patch against commit d378220c96c3c8b6f27dca33e7d8ba03318f9c2d extending libnl with a facility to receive generic netlink messages sent to multicast groups. Essentially it add one new function genl_ctrl_resolve_grp which prototype looks like this int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family_name, const char *grp_name) It resolves the family name and the group name to group id. Then the returned id can be used in nl_socket_add_membership to subscribe to multicast messages. Besides that it adds two more functions uint32_t nl_socket_get_peer_groups(struct nl_sock *sk) void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups) allowing to modify the socket peer groups field. So it's possible to multicast messages from the user space using the legacy interface. Looks like there is no way (or I was not able to find one?) to modify the netlink socket destination group from the user space, when the group id is greater then 32. Signed-off-by: Hauke Mehrtens Signed-off-by: Felix Fietkau [cosmetic style fix] --- include/netlink-types.h | 7 +++++++ include/netlink/genl/ctrl.h | 3 +++ include/netlink/genl/family.h | 4 ++++ include/netlink/socket.h | 10 ++++++++++ 4 files changed, 24 insertions(+) (limited to 'include') diff --git a/include/netlink-types.h b/include/netlink-types.h index 0d00593..65f7f6c 100644 --- a/include/netlink-types.h +++ b/include/netlink-types.h @@ -69,6 +69,13 @@ struct nl_addr #define GENL_OP_HAS_DOIT 2 #define GENL_OP_HAS_DUMPIT 4 +struct genl_family_grp { + struct genl_family *family; /* private */ + struct nl_list_head list; /* private */ + char name[GENL_NAMSIZ]; + u_int32_t id; +}; + struct genl_family_op { uint32_t o_id; diff --git a/include/netlink/genl/ctrl.h b/include/netlink/genl/ctrl.h index 1ae62f4..26a0a99 100644 --- a/include/netlink/genl/ctrl.h +++ b/include/netlink/genl/ctrl.h @@ -29,6 +29,9 @@ extern struct genl_family * genl_ctrl_search_by_name(struct nl_cache *, const char *); extern int genl_ctrl_resolve(struct nl_sock *, const char *); +extern int genl_ctrl_resolve_grp(struct nl_sock *sk, + const char *family, + const char *grp); #ifdef __cplusplus } diff --git a/include/netlink/genl/family.h b/include/netlink/genl/family.h index bdce09d..777c16e 100644 --- a/include/netlink/genl/family.h +++ b/include/netlink/genl/family.h @@ -39,6 +39,7 @@ struct genl_family uint32_t gf_maxattr; struct nl_list_head gf_ops; + struct nl_list_head gf_mc_grps; }; @@ -47,6 +48,9 @@ extern void genl_family_put(struct genl_family *); extern int genl_family_add_op(struct genl_family *, int, int); +extern int genl_family_add_grp(struct genl_family *, + uint32_t , const char *); + /** * @name Attributes diff --git a/include/netlink/socket.h b/include/netlink/socket.h index 9f7f422..bcb934c 100644 --- a/include/netlink/socket.h +++ b/include/netlink/socket.h @@ -166,6 +166,16 @@ static inline void nl_socket_disable_msg_peek(struct nl_sock *sk) sk->s_flags &= ~NL_MSG_PEEK; } +static inline uint32_t nl_socket_get_peer_groups(struct nl_sock *sk) +{ + return sk->s_peer.nl_groups; +} + +static inline void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups) +{ + sk->s_peer.nl_groups = groups; +} + /** * @name Callback Handler * @{ -- cgit v1.2.1