2 * lib/genl/family.c Generic Netlink Family
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
14 * @defgroup genl_family Generic Netlink Family
20 #include <netlink-generic.h>
21 #include <netlink/netlink.h>
22 #include <netlink/genl/genl.h>
23 #include <netlink/genl/family.h>
24 #include <netlink/utils.h>
26 struct nl_object_ops genl_family_ops
;
29 static void family_constructor(struct nl_object
*c
)
31 struct genl_family
*family
= (struct genl_family
*) c
;
33 nl_init_list_head(&family
->gf_ops
);
36 static void family_free_data(struct nl_object
*c
)
38 struct genl_family
*family
= (struct genl_family
*) c
;
39 struct genl_family_op
*ops
, *tmp
;
44 nl_list_for_each_entry_safe(ops
, tmp
, &family
->gf_ops
, o_list
) {
45 nl_list_del(&ops
->o_list
);
50 static int family_clone(struct nl_object
*_dst
, struct nl_object
*_src
)
52 struct genl_family
*dst
= nl_object_priv(_dst
);
53 struct genl_family
*src
= nl_object_priv(_src
);
54 struct genl_family_op
*ops
;
57 nl_list_for_each_entry(ops
, &src
->gf_ops
, o_list
) {
58 err
= genl_family_add_op(dst
, ops
->o_id
, ops
->o_flags
);
66 static int family_compare(struct nl_object
*_a
, struct nl_object
*_b
,
67 uint32_t attrs
, int flags
)
69 struct genl_family
*a
= (struct genl_family
*) _a
;
70 struct genl_family
*b
= (struct genl_family
*) _b
;
73 #define FAM_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, FAMILY_ATTR_##ATTR, a, b, EXPR)
75 diff
|= FAM_DIFF(ID
, a
->gf_id
!= b
->gf_id
);
76 diff
|= FAM_DIFF(VERSION
, a
->gf_version
!= b
->gf_version
);
77 diff
|= FAM_DIFF(HDRSIZE
, a
->gf_hdrsize
!= b
->gf_hdrsize
);
78 diff
|= FAM_DIFF(MAXATTR
, a
->gf_maxattr
!= b
->gf_maxattr
);
79 diff
|= FAM_DIFF(NAME
, strcmp(a
->gf_name
, b
->gf_name
));
92 struct genl_family
*genl_family_alloc(void)
94 return (struct genl_family
*) nl_object_alloc(&genl_family_ops
);
97 void genl_family_put(struct genl_family
*family
)
99 nl_object_put((struct nl_object
*) family
);
105 int genl_family_add_op(struct genl_family
*family
, int id
, int flags
)
107 struct genl_family_op
*op
;
109 op
= calloc(1, sizeof(*op
));
116 nl_list_add_tail(&op
->o_list
, &family
->gf_ops
);
117 family
->ce_mask
|= FAMILY_ATTR_OPS
;
125 struct nl_object_ops genl_family_ops
= {
126 .oo_name
= "genl/family",
127 .oo_size
= sizeof(struct genl_family
),
128 .oo_constructor
= family_constructor
,
129 .oo_free_data
= family_free_data
,
130 .oo_clone
= family_clone
,
131 .oo_compare
= family_compare
,
132 .oo_id_attrs
= FAMILY_ATTR_ID
,