00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef NETLINK_ATTR_H_
00013 #define NETLINK_ATTR_H_
00014
00015 #include <netlink/netlink.h>
00016 #include <netlink/object.h>
00017 #include <netlink/addr.h>
00018 #include <netlink/data.h>
00019
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023
00024 struct nl_msg;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 enum {
00038 NLA_UNSPEC,
00039 NLA_U8,
00040 NLA_U16,
00041 NLA_U32,
00042 NLA_U64,
00043 NLA_STRING,
00044 NLA_FLAG,
00045 NLA_MSECS,
00046 NLA_NESTED,
00047 __NLA_TYPE_MAX,
00048 };
00049
00050 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 struct nla_policy {
00061
00062 uint16_t type;
00063
00064
00065 uint16_t minlen;
00066
00067
00068 uint16_t maxlen;
00069 };
00070
00071
00072 extern int nla_attr_size(int payload);
00073 extern int nla_total_size(int payload);
00074 extern int nla_padlen(int payload);
00075
00076
00077 extern int nla_type(const struct nlattr *);
00078 extern void * nla_data(const struct nlattr *);
00079 extern int nla_len(const struct nlattr *);
00080 extern int nla_ok(const struct nlattr *, int);
00081 extern struct nlattr * nla_next(const struct nlattr *, int *);
00082 extern int nla_parse(struct nlattr **, int, struct nlattr *,
00083 int, struct nla_policy *);
00084 extern int nla_validate(struct nlattr *, int, int,
00085 struct nla_policy *);
00086 extern struct nlattr * nla_find(struct nlattr *, int, int);
00087
00088
00089 extern int nla_memcpy(void *, struct nlattr *, int);
00090 extern size_t nla_strlcpy(char *, const struct nlattr *, size_t);
00091 extern int nla_memcmp(const struct nlattr *, const void *, size_t);
00092 extern int nla_strcmp(const struct nlattr *, const char *);
00093
00094
00095 extern struct nlattr * nla_reserve(struct nl_msg *, int, int);
00096 extern int nla_put(struct nl_msg *, int, int, const void *);
00097 extern int nla_put_data(struct nl_msg *, int, struct nl_data *);
00098 extern int nla_put_addr(struct nl_msg *, int, struct nl_addr *);
00099
00100
00101 extern uint8_t nla_get_u8(struct nlattr *);
00102 extern int nla_put_u8(struct nl_msg *, int, uint8_t);
00103 extern uint16_t nla_get_u16(struct nlattr *);
00104 extern int nla_put_u16(struct nl_msg *, int, uint16_t);
00105 extern uint32_t nla_get_u32(struct nlattr *);
00106 extern int nla_put_u32(struct nl_msg *, int, uint32_t);
00107 extern uint64_t nla_get_u64(struct nlattr *);
00108 extern int nla_put_u64(struct nl_msg *, int, uint64_t);
00109
00110
00111 extern char * nla_get_string(struct nlattr *);
00112 extern char * nla_strdup(struct nlattr *);
00113 extern int nla_put_string(struct nl_msg *, int, const char *);
00114
00115
00116 extern int nla_get_flag(struct nlattr *);
00117 extern int nla_put_flag(struct nl_msg *, int);
00118
00119
00120 extern unsigned long nla_get_msecs(struct nlattr *);
00121 extern int nla_put_msecs(struct nl_msg *, int, unsigned long);
00122
00123
00124 extern int nla_put_nested(struct nl_msg *, int, struct nl_msg *);
00125 extern struct nlattr * nla_nest_start(struct nl_msg *, int);
00126 extern int nla_nest_end(struct nl_msg *, struct nlattr *);
00127 extern int nla_parse_nested(struct nlattr **, int, struct nlattr *,
00128 struct nla_policy *);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 #define NLA_PUT(msg, attrtype, attrlen, data) \
00144 do { \
00145 if (nla_put(msg, attrtype, attrlen, data) < 0) \
00146 goto nla_put_failure; \
00147 } while(0)
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 #define NLA_PUT_TYPE(msg, type, attrtype, value) \
00158 do { \
00159 type __tmp = value; \
00160 NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
00161 } while(0)
00162
00163
00164
00165
00166
00167
00168
00169 #define NLA_PUT_U8(msg, attrtype, value) \
00170 NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
00171
00172
00173
00174
00175
00176
00177
00178 #define NLA_PUT_U16(msg, attrtype, value) \
00179 NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
00180
00181
00182
00183
00184
00185
00186
00187 #define NLA_PUT_U32(msg, attrtype, value) \
00188 NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
00189
00190
00191
00192
00193
00194
00195
00196 #define NLA_PUT_U64(msg, attrtype, value) \
00197 NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
00198
00199
00200
00201
00202
00203
00204
00205 #define NLA_PUT_STRING(msg, attrtype, value) \
00206 NLA_PUT(msg, attrtype, strlen(value) + 1, value)
00207
00208
00209
00210
00211
00212
00213 #define NLA_PUT_FLAG(msg, attrtype) \
00214 NLA_PUT(msg, attrtype, 0, NULL)
00215
00216
00217
00218
00219
00220
00221
00222 #define NLA_PUT_MSECS(msg, attrtype, msecs) \
00223 NLA_PUT_U64(msg, attrtype, msecs)
00224
00225
00226
00227
00228
00229
00230
00231 #define NLA_PUT_ADDR(msg, attrtype, addr) \
00232 NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
00233 nl_addr_get_binary_addr(addr))
00234
00235
00236
00237
00238
00239
00240
00241 #define NLA_PUT_DATA(msg, attrtype, data) \
00242 NLA_PUT(msg, attrtype, nl_data_get_size(data), \
00243 nl_data_get(data))
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 #define nla_for_each_attr(pos, head, len, rem) \
00261 for (pos = head, rem = len; \
00262 nla_ok(pos, rem); \
00263 pos = nla_next(pos, &(rem)))
00264
00265
00266
00267
00268
00269
00270
00271
00272 #define nla_for_each_nested(pos, nla, rem) \
00273 for (pos = nla_data(nla), rem = nla_len(nla); \
00274 nla_ok(pos, rem); \
00275 pos = nla_next(pos, &(rem)))
00276
00277
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283 #endif