Main Page | Class List | File List | Class Members | File Members

netlink.h

Go to the documentation of this file.
00001 #ifndef __LINUX_NETLINK_H 00002 #define __LINUX_NETLINK_H 00003 00004 #define NETLINK_ROUTE 0 /* Routing/device hook */ 00005 #define NETLINK_SKIP 1 /* Reserved for ENskip */ 00006 #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */ 00007 #define NETLINK_FIREWALL 3 /* Firewalling hook */ 00008 #define NETLINK_TCPDIAG 4 /* TCP socket monitoring */ 00009 #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */ 00010 #define NETLINK_ARPD 8 00011 #define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */ 00012 #define NETLINK_IP6_FW 13 00013 #define NETLINK_DNRTMSG 14 /* DECnet routing messages */ 00014 #define NETLINK_TAPBASE 16 /* 16 to 31 are ethertap */ 00015 00016 #define MAX_LINKS 32 00017 00018 struct sockaddr_nl 00019 { 00020 sa_family_t nl_family; /* AF_NETLINK */ 00021 unsigned short nl_pad; /* zero */ 00022 __u32 nl_pid; /* process pid */ 00023 __u32 nl_groups; /* multicast groups mask */ 00024 }; 00025 00026 struct nlmsghdr 00027 { 00028 __u32 nlmsg_len; /* Length of message including header */ 00029 __u16 nlmsg_type; /* Message content */ 00030 __u16 nlmsg_flags; /* Additional flags */ 00031 __u32 nlmsg_seq; /* Sequence number */ 00032 __u32 nlmsg_pid; /* Sending process PID */ 00033 }; 00034 00035 /* Flags values */ 00036 00037 #define NLM_F_REQUEST 1 /* It is request message. */ 00038 #define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */ 00039 #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */ 00040 #define NLM_F_ECHO 8 /* Echo this request */ 00041 00042 /* Modifiers to GET request */ 00043 #define NLM_F_ROOT 0x100 /* specify tree root */ 00044 #define NLM_F_MATCH 0x200 /* return all matching */ 00045 #define NLM_F_ATOMIC 0x400 /* atomic GET */ 00046 #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) 00047 00048 /* Modifiers to NEW request */ 00049 #define NLM_F_REPLACE 0x100 /* Override existing */ 00050 #define NLM_F_EXCL 0x200 /* Do not touch, if it exists */ 00051 #define NLM_F_CREATE 0x400 /* Create, if it does not exist */ 00052 #define NLM_F_APPEND 0x800 /* Add to end of list */ 00053 00054 /* 00055 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL 00056 4.4BSD CHANGE NLM_F_REPLACE 00057 00058 True CHANGE NLM_F_CREATE|NLM_F_REPLACE 00059 Append NLM_F_CREATE 00060 Check NLM_F_EXCL 00061 */ 00062 00063 #define NLMSG_ALIGNTO 4 00064 #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) 00065 #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr))) 00066 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) 00067 #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0))) 00068 #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \ 00069 (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len))) 00070 #define NLMSG_OK(nlh,len) ((len) > 0 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ 00071 (nlh)->nlmsg_len <= (len)) 00072 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len))) 00073 00074 #define NLMSG_NOOP 0x1 /* Nothing. */ 00075 #define NLMSG_ERROR 0x2 /* Error */ 00076 #define NLMSG_DONE 0x3 /* End of a dump */ 00077 #define NLMSG_OVERRUN 0x4 /* Data lost */ 00078 00079 struct nlmsgerr 00080 { 00081 int error; 00082 struct nlmsghdr msg; 00083 }; 00084 00085 #define NET_MAJOR 36 /* Major 36 is reserved for networking */ 00086 00087 #ifdef __KERNEL__ 00088 00089 struct netlink_skb_parms 00090 { 00091 struct ucred creds; /* Skb credentials */ 00092 __u32 pid; 00093 __u32 groups; 00094 __u32 dst_pid; 00095 __u32 dst_groups; 00096 kernel_cap_t eff_cap; 00097 }; 00098 00099 #define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb)) 00100 #define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds) 00101 00102 00103 extern int netlink_attach(int unit, int (*function)(int,struct sk_buff *skb)); 00104 extern void netlink_detach(int unit); 00105 extern int netlink_post(int unit, struct sk_buff *skb); 00106 extern int init_netlink(void); 00107 extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)); 00108 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err); 00109 extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock); 00110 extern void netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid, 00111 __u32 group, int allocation); 00112 extern void netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code); 00113 extern int netlink_register_notifier(struct notifier_block *nb); 00114 extern int netlink_unregister_notifier(struct notifier_block *nb); 00115 00116 /* 00117 * skb should fit one page. This choice is good for headerless malloc. 00118 * 00119 * FIXME: What is the best size for SLAB???? --ANK 00120 */ 00121 #define NLMSG_GOODSIZE (PAGE_SIZE - ((sizeof(struct sk_buff)+0xF)&~0xF)) 00122 00123 00124 struct netlink_callback 00125 { 00126 struct sk_buff *skb; 00127 struct nlmsghdr *nlh; 00128 int (*dump)(struct sk_buff * skb, struct netlink_callback *cb); 00129 int (*done)(struct netlink_callback *cb); 00130 int family; 00131 long args[4]; 00132 }; 00133 00134 struct netlink_notify 00135 { 00136 int pid; 00137 int protocol; 00138 }; 00139 00140 static __inline__ struct nlmsghdr * 00141 __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len) 00142 { 00143 struct nlmsghdr *nlh; 00144 int size = NLMSG_LENGTH(len); 00145 00146 nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size)); 00147 nlh->nlmsg_type = type; 00148 nlh->nlmsg_len = size; 00149 nlh->nlmsg_flags = 0; 00150 nlh->nlmsg_pid = pid; 00151 nlh->nlmsg_seq = seq; 00152 return nlh; 00153 } 00154 00155 #define NLMSG_PUT(skb, pid, seq, type, len) \ 00156 ({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \ 00157 __nlmsg_put(skb, pid, seq, type, len); }) 00158 00159 extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, 00160 struct nlmsghdr *nlh, 00161 int (*dump)(struct sk_buff *skb, struct netlink_callback*), 00162 int (*done)(struct netlink_callback*)); 00163 00164 #define NL_NONROOT_RECV 0x1 00165 #define NL_NONROOT_SEND 0x2 00166 extern void netlink_set_nonroot(int protocol, unsigned flag); 00167 00168 00169 #endif /* __KERNEL__ */ 00170 00171 #endif /* __LINUX_NETLINK_H */

Generated on Wed Dec 1 21:25:32 2004 for Linux 2.4.23 Networking by doxygen 1.3.8