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