b7cf48fb78044e27ed8dd792c8558a213cb6c343
[openwrt/openwrt.git] / package / libs / libnl-tiny / src / include / netlink / genl / family.h
1 /*
2 * netlink/genl/family.h Generic Netlink Family
3 *
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
7 * of the License.
8 *
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 */
11
12 #ifndef NETLINK_GENL_FAMILY_H_
13 #define NETLINK_GENL_FAMILY_H_
14
15 #include <netlink/netlink.h>
16 #include <netlink/cache.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /** @cond SKIP */
23 #define FAMILY_ATTR_ID 0x01
24 #define FAMILY_ATTR_NAME 0x02
25 #define FAMILY_ATTR_VERSION 0x04
26 #define FAMILY_ATTR_HDRSIZE 0x08
27 #define FAMILY_ATTR_MAXATTR 0x10
28 #define FAMILY_ATTR_OPS 0x20
29
30
31 struct genl_family
32 {
33 NLHDR_COMMON
34
35 uint16_t gf_id;
36 char gf_name[GENL_NAMSIZ];
37 uint32_t gf_version;
38 uint32_t gf_hdrsize;
39 uint32_t gf_maxattr;
40
41 struct nl_list_head gf_ops;
42 struct nl_list_head gf_mc_grps;
43 };
44
45
46 extern struct genl_family * genl_family_alloc(void);
47 extern void genl_family_put(struct genl_family *);
48
49 extern int genl_family_add_op(struct genl_family *,
50 int, int);
51 extern int genl_family_add_grp(struct genl_family *,
52 uint32_t , const char *);
53
54
55 /**
56 * @name Attributes
57 * @{
58 */
59
60 static inline unsigned int genl_family_get_id(struct genl_family *family)
61 {
62 if (family->ce_mask & FAMILY_ATTR_ID)
63 return family->gf_id;
64 else
65 return GENL_ID_GENERATE;
66 }
67
68 static inline void genl_family_set_id(struct genl_family *family, unsigned int id)
69 {
70 family->gf_id = id;
71 family->ce_mask |= FAMILY_ATTR_ID;
72 }
73
74 static inline char *genl_family_get_name(struct genl_family *family)
75 {
76 if (family->ce_mask & FAMILY_ATTR_NAME)
77 return family->gf_name;
78 else
79 return NULL;
80 }
81
82 static inline void genl_family_set_name(struct genl_family *family, const char *name)
83 {
84 strncpy(family->gf_name, name, GENL_NAMSIZ-1);
85 family->ce_mask |= FAMILY_ATTR_NAME;
86 }
87
88 static inline uint8_t genl_family_get_version(struct genl_family *family)
89 {
90 if (family->ce_mask & FAMILY_ATTR_VERSION)
91 return family->gf_version;
92 else
93 return 0;
94 }
95
96 static inline void genl_family_set_version(struct genl_family *family, uint8_t version)
97 {
98 family->gf_version = version;
99 family->ce_mask |= FAMILY_ATTR_VERSION;
100 }
101
102 static inline uint32_t genl_family_get_hdrsize(struct genl_family *family)
103 {
104 if (family->ce_mask & FAMILY_ATTR_HDRSIZE)
105 return family->gf_hdrsize;
106 else
107 return 0;
108 }
109
110 static inline void genl_family_set_hdrsize(struct genl_family *family, uint32_t hdrsize)
111 {
112 family->gf_hdrsize = hdrsize;
113 family->ce_mask |= FAMILY_ATTR_HDRSIZE;
114 }
115
116 static inline uint32_t genl_family_get_maxattr(struct genl_family *family)
117 {
118 if (family->ce_mask & FAMILY_ATTR_MAXATTR)
119 return family->gf_maxattr;
120 else
121 return family->gf_maxattr;
122 }
123
124 static inline void genl_family_set_maxattr(struct genl_family *family, uint32_t maxattr)
125 {
126 family->gf_maxattr = maxattr;
127 family->ce_mask |= FAMILY_ATTR_MAXATTR;
128 }
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif