Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
422 | giacomo | 1 | #ifndef __LINUX_NETLINK_H |
2 | #define __LINUX_NETLINK_H |
||
3 | |||
4 | #include <linux/socket.h> /* for sa_family_t */ |
||
5 | #include <linux/types.h> |
||
6 | |||
7 | #define NETLINK_ROUTE 0 /* Routing/device hook */ |
||
8 | #define NETLINK_SKIP 1 /* Reserved for ENskip */ |
||
9 | #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ |
||
10 | #define NETLINK_FIREWALL 3 /* Firewalling hook */ |
||
11 | #define NETLINK_TCPDIAG 4 /* TCP socket monitoring */ |
||
12 | #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */ |
||
13 | #define NETLINK_XFRM 6 /* ipsec */ |
||
14 | #define NETLINK_ARPD 8 |
||
15 | #define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */ |
||
16 | #define NETLINK_IP6_FW 13 |
||
17 | #define NETLINK_DNRTMSG 14 /* DECnet routing messages */ |
||
18 | #define NETLINK_TAPBASE 16 /* 16 to 31 are ethertap */ |
||
19 | |||
20 | #define MAX_LINKS 32 |
||
21 | |||
22 | struct sockaddr_nl |
||
23 | { |
||
24 | sa_family_t nl_family; /* AF_NETLINK */ |
||
25 | unsigned short nl_pad; /* zero */ |
||
26 | __u32 nl_pid; /* process pid */ |
||
27 | __u32 nl_groups; /* multicast groups mask */ |
||
28 | }; |
||
29 | |||
30 | struct nlmsghdr |
||
31 | { |
||
32 | __u32 nlmsg_len; /* Length of message including header */ |
||
33 | __u16 nlmsg_type; /* Message content */ |
||
34 | __u16 nlmsg_flags; /* Additional flags */ |
||
35 | __u32 nlmsg_seq; /* Sequence number */ |
||
36 | __u32 nlmsg_pid; /* Sending process PID */ |
||
37 | }; |
||
38 | |||
39 | /* Flags values */ |
||
40 | |||
41 | #define NLM_F_REQUEST 1 /* It is request message. */ |
||
42 | #define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */ |
||
43 | #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */ |
||
44 | #define NLM_F_ECHO 8 /* Echo this request */ |
||
45 | |||
46 | /* Modifiers to GET request */ |
||
47 | #define NLM_F_ROOT 0x100 /* specify tree root */ |
||
48 | #define NLM_F_MATCH 0x200 /* return all matching */ |
||
49 | #define NLM_F_ATOMIC 0x400 /* atomic GET */ |
||
50 | #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) |
||
51 | |||
52 | /* Modifiers to NEW request */ |
||
53 | #define NLM_F_REPLACE 0x100 /* Override existing */ |
||
54 | #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */ |
||
55 | #define NLM_F_CREATE 0x400 /* Create, if it does not exist */ |
||
56 | #define NLM_F_APPEND 0x800 /* Add to end of list */ |
||
57 | |||
58 | /* |
||
59 | 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL |
||
60 | 4.4BSD CHANGE NLM_F_REPLACE |
||
61 | |||
62 | True CHANGE NLM_F_CREATE|NLM_F_REPLACE |
||
63 | Append NLM_F_CREATE |
||
64 | Check NLM_F_EXCL |
||
65 | */ |
||
66 | |||
67 | #define NLMSG_ALIGNTO 4 |
||
68 | #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) |
||
69 | #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr))) |
||
70 | #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) |
||
71 | #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0))) |
||
72 | #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ |
||
73 | (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len))) |
||
74 | #define NLMSG_OK(nlh,len) ((len) > 0 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ |
||
75 | (nlh)->nlmsg_len <= (len)) |
||
76 | #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len))) |
||
77 | |||
78 | #define NLMSG_NOOP 0x1 /* Nothing. */ |
||
79 | #define NLMSG_ERROR 0x2 /* Error */ |
||
80 | #define NLMSG_DONE 0x3 /* End of a dump */ |
||
81 | #define NLMSG_OVERRUN 0x4 /* Data lost */ |
||
82 | |||
83 | struct nlmsgerr |
||
84 | { |
||
85 | int error; |
||
86 | struct nlmsghdr msg; |
||
87 | }; |
||
88 | |||
89 | #define NET_MAJOR 36 /* Major 36 is reserved for networking */ |
||
90 | |||
91 | #ifdef __KERNEL__ |
||
92 | |||
93 | #include <linux/capability.h> |
||
94 | |||
95 | struct netlink_skb_parms |
||
96 | { |
||
97 | struct ucred creds; /* Skb credentials */ |
||
98 | __u32 pid; |
||
99 | __u32 groups; |
||
100 | __u32 dst_pid; |
||
101 | __u32 dst_groups; |
||
102 | kernel_cap_t eff_cap; |
||
103 | }; |
||
104 | |||
105 | #define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb)) |
||
106 | #define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds) |
||
107 | |||
108 | |||
109 | extern int netlink_attach(int unit, int (*function)(int,struct sk_buff *skb)); |
||
110 | extern void netlink_detach(int unit); |
||
111 | extern int netlink_post(int unit, struct sk_buff *skb); |
||
112 | extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)); |
||
113 | extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err); |
||
114 | extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock); |
||
115 | extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid, |
||
116 | __u32 group, int allocation); |
||
117 | extern void netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code); |
||
118 | extern int netlink_register_notifier(struct notifier_block *nb); |
||
119 | extern int netlink_unregister_notifier(struct notifier_block *nb); |
||
120 | |||
121 | /* |
||
122 | * skb should fit one page. This choice is good for headerless malloc. |
||
123 | * |
||
124 | * FIXME: What is the best size for SLAB???? --ANK |
||
125 | */ |
||
126 | #define NLMSG_GOODSIZE (PAGE_SIZE - ((sizeof(struct sk_buff)+0xF)&~0xF)) |
||
127 | |||
128 | |||
129 | struct netlink_callback |
||
130 | { |
||
131 | struct sk_buff *skb; |
||
132 | struct nlmsghdr *nlh; |
||
133 | int (*dump)(struct sk_buff * skb, struct netlink_callback *cb); |
||
134 | int (*done)(struct netlink_callback *cb); |
||
135 | int family; |
||
136 | long args[4]; |
||
137 | }; |
||
138 | |||
139 | struct netlink_notify |
||
140 | { |
||
141 | int pid; |
||
142 | int protocol; |
||
143 | }; |
||
144 | |||
145 | static __inline__ struct nlmsghdr * |
||
146 | __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len) |
||
147 | { |
||
148 | struct nlmsghdr *nlh; |
||
149 | int size = NLMSG_LENGTH(len); |
||
150 | |||
151 | nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size)); |
||
152 | nlh->nlmsg_type = type; |
||
153 | nlh->nlmsg_len = size; |
||
154 | nlh->nlmsg_flags = 0; |
||
155 | nlh->nlmsg_pid = pid; |
||
156 | nlh->nlmsg_seq = seq; |
||
157 | return nlh; |
||
158 | } |
||
159 | |||
160 | #define NLMSG_PUT(skb, pid, seq, type, len) \ |
||
161 | ({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \ |
||
162 | __nlmsg_put(skb, pid, seq, type, len); }) |
||
163 | |||
164 | extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, |
||
165 | struct nlmsghdr *nlh, |
||
166 | int (*dump)(struct sk_buff *skb, struct netlink_callback*), |
||
167 | int (*done)(struct netlink_callback*)); |
||
168 | |||
169 | |||
170 | #define NL_NONROOT_RECV 0x1 |
||
171 | #define NL_NONROOT_SEND 0x2 |
||
172 | extern void netlink_set_nonroot(int protocol, unsigned flag); |
||
173 | |||
174 | #endif /* __KERNEL__ */ |
||
175 | |||
176 | #endif /* __LINUX_NETLINK_H */ |