summaryrefslogtreecommitdiff
path: root/genl_family.c
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke.mehrtens@intel.com>2016-06-29 23:13:58 +0200
committerrofl0r <rofl0r@users.noreply.github.com>2022-09-16 01:22:58 +0000
commita62eac97f954c6e025fb1d45e7c289d14aca2305 (patch)
tree2ead617280b2fba4115a0d6f747e2fdc70e98633 /genl_family.c
parent7d3593619805abbd923ef02ee257c006476f64cd (diff)
downloadlibnl-tiny-a62eac97f954c6e025fb1d45e7c289d14aca2305.tar.gz
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 <dima.ky@gmail.com> 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 <hauke.mehrtens@intel.com> Signed-off-by: Felix Fietkau <nbd@nbd.name> [cosmetic style fix]
Diffstat (limited to 'genl_family.c')
-rw-r--r--genl_family.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/genl_family.c b/genl_family.c
index 88aaad9..221acfa 100644
--- a/genl_family.c
+++ b/genl_family.c
@@ -31,12 +31,14 @@ static void family_constructor(struct nl_object *c)
struct genl_family *family = (struct genl_family *) c;
nl_init_list_head(&family->gf_ops);
+ nl_init_list_head(&family->gf_mc_grps);
}
static void family_free_data(struct nl_object *c)
{
struct genl_family *family = (struct genl_family *) c;
struct genl_family_op *ops, *tmp;
+ struct genl_family_grp *grp, *t_grp;
if (family == NULL)
return;
@@ -45,6 +47,12 @@ static void family_free_data(struct nl_object *c)
nl_list_del(&ops->o_list);
free(ops);
}
+
+ nl_list_for_each_entry_safe(grp, t_grp, &family->gf_mc_grps, list) {
+ nl_list_del(&grp->list);
+ free(grp);
+ }
+
}
static int family_clone(struct nl_object *_dst, struct nl_object *_src)
@@ -52,6 +60,7 @@ static int family_clone(struct nl_object *_dst, struct nl_object *_src)
struct genl_family *dst = nl_object_priv(_dst);
struct genl_family *src = nl_object_priv(_src);
struct genl_family_op *ops;
+ struct genl_family_grp *grp;
int err;
nl_list_for_each_entry(ops, &src->gf_ops, o_list) {
@@ -59,6 +68,13 @@ static int family_clone(struct nl_object *_dst, struct nl_object *_src)
if (err < 0)
return err;
}
+
+ nl_list_for_each_entry(grp, &src->gf_mc_grps, list) {
+ err = genl_family_add_grp(dst, grp->id, grp->name);
+ if (err < 0)
+ return err;
+ }
+
return 0;
}
@@ -119,6 +135,23 @@ int genl_family_add_op(struct genl_family *family, int id, int flags)
return 0;
}
+int genl_family_add_grp(struct genl_family *family, uint32_t id,
+ const char *name)
+{
+ struct genl_family_grp *grp;
+
+ grp = calloc(1, sizeof(*grp));
+ if (grp == NULL)
+ return -NLE_NOMEM;
+
+ grp->id = id;
+ strncpy(grp->name, name, GENL_NAMSIZ - 1);
+
+ nl_list_add_tail(&grp->list, &family->gf_mc_grps);
+
+ return 0;
+}
+
/** @} */
/** @cond SKIP */