69089e44a1a89b2866aa484cdcfc5d0844b0c7c9
[openvswitch] / datapath / linux-2.4 / compat-2.4 / include / linux / netlink.h
1 #ifndef __LINUX_NETLINK_WRAPPER_H
2 #define __LINUX_NETLINK_WRAPPER_H 1
3
4 #include_next <linux/netlink.h>
5
6 #define NETLINK_GENERIC                16
7
8 #undef NLMSG_LENGTH
9 #define NLMSG_HDRLEN    ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
10 #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
11
12 #define NLMSG_MIN_TYPE         0x10    /* < 0x10: reserved control messages */
13
14 enum {
15        NETLINK_UNCONNECTED = 0,
16        NETLINK_CONNECTED,
17 };
18
19 /*
20  *  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
21  * +---------------------+- - -+- - - - - - - - - -+- - -+
22  * |        Header       | Pad |     Payload       | Pad |
23  * |   (struct nlattr)   | ing |                   | ing |
24  * +---------------------+- - -+- - - - - - - - - -+- - -+
25  *  <-------------- nlattr->nla_len -------------->
26  */
27
28 struct nlattr
29 {
30        __u16           nla_len;
31        __u16           nla_type;
32 };
33
34 #define NLA_ALIGNTO            4
35 #define NLA_ALIGN(len)         (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
36 #define NLA_HDRLEN             ((int) NLA_ALIGN(sizeof(struct nlattr)))
37
38 #ifdef __KERNEL__
39
40 #include <linux/capability.h>
41 #include <linux/skbuff.h>
42
43 static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
44 {
45        return (struct nlmsghdr *)skb->data;
46 }
47
48 #define __nlmsg_put __rpl_nlmsg_put
49 static __inline__ struct nlmsghdr *
50 __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
51 {
52         struct nlmsghdr *nlh;
53         int size = NLMSG_LENGTH(len);
54
55         nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size));
56         nlh->nlmsg_type = type;
57         nlh->nlmsg_len = size;
58         nlh->nlmsg_flags = flags;
59         nlh->nlmsg_pid = pid;
60         nlh->nlmsg_seq = seq;
61         memset(NLMSG_DATA(nlh) + len, 0, NLMSG_ALIGN(size) - size);
62         return nlh;
63 }
64
65 #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
66
67 #undef NLMSG_NEW
68 #define NLMSG_NEW(skb, pid, seq, type, len, flags) \
69 ({      if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) \
70                 goto nlmsg_failure; \
71         __nlmsg_put(skb, pid, seq, type, len, flags); })
72 #endif
73
74 #undef NLMSG_PUT
75 #define NLMSG_PUT(skb, pid, seq, type, len) \
76         NLMSG_NEW(skb, pid, seq, type, len, 0)
77
78 #endif