af_netlink.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
  1. /*
  2. * NETLINK Kernel-user communication protocol.
  3. *
  4. * Authors: Alan Cox <alan@redhat.com>
  5. * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * Tue Jun 26 14:36:48 MEST 2001 Herbert "herp" Rosmanith
  13. * added netlink_proto_exit
  14. * Tue Jan 22 18:32:44 BRST 2002 Arnaldo C. de Melo <acme@conectiva.com.br>
  15. * use nlk_sk, as sk->protinfo is on a diet 8)
  16. * Fri Jul 22 19:51:12 MEST 2005 Harald Welte <laforge@gnumonks.org>
  17. * - inc module use count of module that owns
  18. * the kernel socket in case userspace opens
  19. * socket of same protocol
  20. * - remove all module support, since netlink is
  21. * mandatory if CONFIG_NET=y these days
  22. */
  23. #include <linux/module.h>
  24. #include <linux/capability.h>
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/signal.h>
  28. #include <linux/sched.h>
  29. #include <linux/errno.h>
  30. #include <linux/string.h>
  31. #include <linux/stat.h>
  32. #include <linux/socket.h>
  33. #include <linux/un.h>
  34. #include <linux/fcntl.h>
  35. #include <linux/termios.h>
  36. #include <linux/sockios.h>
  37. #include <linux/net.h>
  38. #include <linux/fs.h>
  39. #include <linux/slab.h>
  40. #include <asm/uaccess.h>
  41. #include <linux/skbuff.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/rtnetlink.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/notifier.h>
  47. #include <linux/security.h>
  48. #include <linux/jhash.h>
  49. #include <linux/jiffies.h>
  50. #include <linux/random.h>
  51. #include <linux/bitops.h>
  52. #include <linux/mm.h>
  53. #include <linux/types.h>
  54. #include <linux/audit.h>
  55. #include <linux/selinux.h>
  56. #include <linux/mutex.h>
  57. #include <net/net_namespace.h>
  58. #include <net/sock.h>
  59. #include <net/scm.h>
  60. #include <net/netlink.h>
  61. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  62. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  63. struct netlink_sock {
  64. /* struct sock has to be the first member of netlink_sock */
  65. struct sock sk;
  66. u32 pid;
  67. u32 dst_pid;
  68. u32 dst_group;
  69. u32 flags;
  70. u32 subscriptions;
  71. u32 ngroups;
  72. unsigned long *groups;
  73. unsigned long state;
  74. wait_queue_head_t wait;
  75. struct netlink_callback *cb;
  76. struct mutex *cb_mutex;
  77. struct mutex cb_def_mutex;
  78. void (*data_ready)(struct sock *sk, int bytes);
  79. struct module *module;
  80. };
  81. #define NETLINK_KERNEL_SOCKET 0x1
  82. #define NETLINK_RECV_PKTINFO 0x2
  83. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  84. {
  85. return container_of(sk, struct netlink_sock, sk);
  86. }
  87. struct nl_pid_hash {
  88. struct hlist_head *table;
  89. unsigned long rehash_time;
  90. unsigned int mask;
  91. unsigned int shift;
  92. unsigned int entries;
  93. unsigned int max_shift;
  94. u32 rnd;
  95. };
  96. struct netlink_table {
  97. struct nl_pid_hash hash;
  98. struct hlist_head mc_list;
  99. unsigned long *listeners;
  100. unsigned int nl_nonroot;
  101. unsigned int groups;
  102. struct mutex *cb_mutex;
  103. struct module *module;
  104. int registered;
  105. };
  106. static struct netlink_table *nl_table;
  107. static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait);
  108. static int netlink_dump(struct sock *sk);
  109. static void netlink_destroy_callback(struct netlink_callback *cb);
  110. static void netlink_queue_skip(struct nlmsghdr *nlh, struct sk_buff *skb);
  111. static DEFINE_RWLOCK(nl_table_lock);
  112. static atomic_t nl_table_users = ATOMIC_INIT(0);
  113. static ATOMIC_NOTIFIER_HEAD(netlink_chain);
  114. static u32 netlink_group_mask(u32 group)
  115. {
  116. return group ? 1 << (group - 1) : 0;
  117. }
  118. static struct hlist_head *nl_pid_hashfn(struct nl_pid_hash *hash, u32 pid)
  119. {
  120. return &hash->table[jhash_1word(pid, hash->rnd) & hash->mask];
  121. }
  122. static void netlink_sock_destruct(struct sock *sk)
  123. {
  124. struct netlink_sock *nlk = nlk_sk(sk);
  125. if (nlk->cb) {
  126. if (nlk->cb->done)
  127. nlk->cb->done(nlk->cb);
  128. netlink_destroy_callback(nlk->cb);
  129. }
  130. skb_queue_purge(&sk->sk_receive_queue);
  131. if (!sock_flag(sk, SOCK_DEAD)) {
  132. printk("Freeing alive netlink socket %p\n", sk);
  133. return;
  134. }
  135. BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
  136. BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
  137. BUG_TRAP(!nlk_sk(sk)->groups);
  138. }
  139. /* This lock without WQ_FLAG_EXCLUSIVE is good on UP and it is _very_ bad on SMP.
  140. * Look, when several writers sleep and reader wakes them up, all but one
  141. * immediately hit write lock and grab all the cpus. Exclusive sleep solves
  142. * this, _but_ remember, it adds useless work on UP machines.
  143. */
  144. static void netlink_table_grab(void)
  145. {
  146. write_lock_irq(&nl_table_lock);
  147. if (atomic_read(&nl_table_users)) {
  148. DECLARE_WAITQUEUE(wait, current);
  149. add_wait_queue_exclusive(&nl_table_wait, &wait);
  150. for(;;) {
  151. set_current_state(TASK_UNINTERRUPTIBLE);
  152. if (atomic_read(&nl_table_users) == 0)
  153. break;
  154. write_unlock_irq(&nl_table_lock);
  155. schedule();
  156. write_lock_irq(&nl_table_lock);
  157. }
  158. __set_current_state(TASK_RUNNING);
  159. remove_wait_queue(&nl_table_wait, &wait);
  160. }
  161. }
  162. static __inline__ void netlink_table_ungrab(void)
  163. {
  164. write_unlock_irq(&nl_table_lock);
  165. wake_up(&nl_table_wait);
  166. }
  167. static __inline__ void
  168. netlink_lock_table(void)
  169. {
  170. /* read_lock() synchronizes us to netlink_table_grab */
  171. read_lock(&nl_table_lock);
  172. atomic_inc(&nl_table_users);
  173. read_unlock(&nl_table_lock);
  174. }
  175. static __inline__ void
  176. netlink_unlock_table(void)
  177. {
  178. if (atomic_dec_and_test(&nl_table_users))
  179. wake_up(&nl_table_wait);
  180. }
  181. static __inline__ struct sock *netlink_lookup(struct net *net, int protocol, u32 pid)
  182. {
  183. struct nl_pid_hash *hash = &nl_table[protocol].hash;
  184. struct hlist_head *head;
  185. struct sock *sk;
  186. struct hlist_node *node;
  187. read_lock(&nl_table_lock);
  188. head = nl_pid_hashfn(hash, pid);
  189. sk_for_each(sk, node, head) {
  190. if ((sk->sk_net == net) && (nlk_sk(sk)->pid == pid)) {
  191. sock_hold(sk);
  192. goto found;
  193. }
  194. }
  195. sk = NULL;
  196. found:
  197. read_unlock(&nl_table_lock);
  198. return sk;
  199. }
  200. static inline struct hlist_head *nl_pid_hash_alloc(size_t size)
  201. {
  202. if (size <= PAGE_SIZE)
  203. return kmalloc(size, GFP_ATOMIC);
  204. else
  205. return (struct hlist_head *)
  206. __get_free_pages(GFP_ATOMIC, get_order(size));
  207. }
  208. static inline void nl_pid_hash_free(struct hlist_head *table, size_t size)
  209. {
  210. if (size <= PAGE_SIZE)
  211. kfree(table);
  212. else
  213. free_pages((unsigned long)table, get_order(size));
  214. }
  215. static int nl_pid_hash_rehash(struct nl_pid_hash *hash, int grow)
  216. {
  217. unsigned int omask, mask, shift;
  218. size_t osize, size;
  219. struct hlist_head *otable, *table;
  220. int i;
  221. omask = mask = hash->mask;
  222. osize = size = (mask + 1) * sizeof(*table);
  223. shift = hash->shift;
  224. if (grow) {
  225. if (++shift > hash->max_shift)
  226. return 0;
  227. mask = mask * 2 + 1;
  228. size *= 2;
  229. }
  230. table = nl_pid_hash_alloc(size);
  231. if (!table)
  232. return 0;
  233. memset(table, 0, size);
  234. otable = hash->table;
  235. hash->table = table;
  236. hash->mask = mask;
  237. hash->shift = shift;
  238. get_random_bytes(&hash->rnd, sizeof(hash->rnd));
  239. for (i = 0; i <= omask; i++) {
  240. struct sock *sk;
  241. struct hlist_node *node, *tmp;
  242. sk_for_each_safe(sk, node, tmp, &otable[i])
  243. __sk_add_node(sk, nl_pid_hashfn(hash, nlk_sk(sk)->pid));
  244. }
  245. nl_pid_hash_free(otable, osize);
  246. hash->rehash_time = jiffies + 10 * 60 * HZ;
  247. return 1;
  248. }
  249. static inline int nl_pid_hash_dilute(struct nl_pid_hash *hash, int len)
  250. {
  251. int avg = hash->entries >> hash->shift;
  252. if (unlikely(avg > 1) && nl_pid_hash_rehash(hash, 1))
  253. return 1;
  254. if (unlikely(len > avg) && time_after(jiffies, hash->rehash_time)) {
  255. nl_pid_hash_rehash(hash, 0);
  256. return 1;
  257. }
  258. return 0;
  259. }
  260. static const struct proto_ops netlink_ops;
  261. static void
  262. netlink_update_listeners(struct sock *sk)
  263. {
  264. struct netlink_table *tbl = &nl_table[sk->sk_protocol];
  265. struct hlist_node *node;
  266. unsigned long mask;
  267. unsigned int i;
  268. for (i = 0; i < NLGRPLONGS(tbl->groups); i++) {
  269. mask = 0;
  270. sk_for_each_bound(sk, node, &tbl->mc_list) {
  271. if (i < NLGRPLONGS(nlk_sk(sk)->ngroups))
  272. mask |= nlk_sk(sk)->groups[i];
  273. }
  274. tbl->listeners[i] = mask;
  275. }
  276. /* this function is only called with the netlink table "grabbed", which
  277. * makes sure updates are visible before bind or setsockopt return. */
  278. }
  279. static int netlink_insert(struct sock *sk, struct net *net, u32 pid)
  280. {
  281. struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash;
  282. struct hlist_head *head;
  283. int err = -EADDRINUSE;
  284. struct sock *osk;
  285. struct hlist_node *node;
  286. int len;
  287. netlink_table_grab();
  288. head = nl_pid_hashfn(hash, pid);
  289. len = 0;
  290. sk_for_each(osk, node, head) {
  291. if ((osk->sk_net == net) && (nlk_sk(osk)->pid == pid))
  292. break;
  293. len++;
  294. }
  295. if (node)
  296. goto err;
  297. err = -EBUSY;
  298. if (nlk_sk(sk)->pid)
  299. goto err;
  300. err = -ENOMEM;
  301. if (BITS_PER_LONG > 32 && unlikely(hash->entries >= UINT_MAX))
  302. goto err;
  303. if (len && nl_pid_hash_dilute(hash, len))
  304. head = nl_pid_hashfn(hash, pid);
  305. hash->entries++;
  306. nlk_sk(sk)->pid = pid;
  307. sk_add_node(sk, head);
  308. err = 0;
  309. err:
  310. netlink_table_ungrab();
  311. return err;
  312. }
  313. static void netlink_remove(struct sock *sk)
  314. {
  315. netlink_table_grab();
  316. if (sk_del_node_init(sk))
  317. nl_table[sk->sk_protocol].hash.entries--;
  318. if (nlk_sk(sk)->subscriptions)
  319. __sk_del_bind_node(sk);
  320. netlink_table_ungrab();
  321. }
  322. static struct proto netlink_proto = {
  323. .name = "NETLINK",
  324. .owner = THIS_MODULE,
  325. .obj_size = sizeof(struct netlink_sock),
  326. };
  327. static int __netlink_create(struct net *net, struct socket *sock,
  328. struct mutex *cb_mutex, int protocol)
  329. {
  330. struct sock *sk;
  331. struct netlink_sock *nlk;
  332. sock->ops = &netlink_ops;
  333. sk = sk_alloc(net, PF_NETLINK, GFP_KERNEL, &netlink_proto, 1);
  334. if (!sk)
  335. return -ENOMEM;
  336. sock_init_data(sock, sk);
  337. nlk = nlk_sk(sk);
  338. if (cb_mutex)
  339. nlk->cb_mutex = cb_mutex;
  340. else {
  341. nlk->cb_mutex = &nlk->cb_def_mutex;
  342. mutex_init(nlk->cb_mutex);
  343. }
  344. init_waitqueue_head(&nlk->wait);
  345. sk->sk_destruct = netlink_sock_destruct;
  346. sk->sk_protocol = protocol;
  347. return 0;
  348. }
  349. static int netlink_create(struct net *net, struct socket *sock, int protocol)
  350. {
  351. struct module *module = NULL;
  352. struct mutex *cb_mutex;
  353. struct netlink_sock *nlk;
  354. int err = 0;
  355. sock->state = SS_UNCONNECTED;
  356. if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
  357. return -ESOCKTNOSUPPORT;
  358. if (protocol<0 || protocol >= MAX_LINKS)
  359. return -EPROTONOSUPPORT;
  360. netlink_lock_table();
  361. #ifdef CONFIG_KMOD
  362. if (!nl_table[protocol].registered) {
  363. netlink_unlock_table();
  364. request_module("net-pf-%d-proto-%d", PF_NETLINK, protocol);
  365. netlink_lock_table();
  366. }
  367. #endif
  368. if (nl_table[protocol].registered &&
  369. try_module_get(nl_table[protocol].module))
  370. module = nl_table[protocol].module;
  371. cb_mutex = nl_table[protocol].cb_mutex;
  372. netlink_unlock_table();
  373. if ((err = __netlink_create(net, sock, cb_mutex, protocol)) < 0)
  374. goto out_module;
  375. nlk = nlk_sk(sock->sk);
  376. nlk->module = module;
  377. out:
  378. return err;
  379. out_module:
  380. module_put(module);
  381. goto out;
  382. }
  383. static int netlink_release(struct socket *sock)
  384. {
  385. struct sock *sk = sock->sk;
  386. struct netlink_sock *nlk;
  387. if (!sk)
  388. return 0;
  389. netlink_remove(sk);
  390. sock_orphan(sk);
  391. nlk = nlk_sk(sk);
  392. /*
  393. * OK. Socket is unlinked, any packets that arrive now
  394. * will be purged.
  395. */
  396. sock->sk = NULL;
  397. wake_up_interruptible_all(&nlk->wait);
  398. skb_queue_purge(&sk->sk_write_queue);
  399. if (nlk->pid && !nlk->subscriptions) {
  400. struct netlink_notify n = {
  401. .net = sk->sk_net,
  402. .protocol = sk->sk_protocol,
  403. .pid = nlk->pid,
  404. };
  405. atomic_notifier_call_chain(&netlink_chain,
  406. NETLINK_URELEASE, &n);
  407. }
  408. module_put(nlk->module);
  409. netlink_table_grab();
  410. if (nlk->flags & NETLINK_KERNEL_SOCKET) {
  411. kfree(nl_table[sk->sk_protocol].listeners);
  412. nl_table[sk->sk_protocol].module = NULL;
  413. nl_table[sk->sk_protocol].registered = 0;
  414. } else if (nlk->subscriptions)
  415. netlink_update_listeners(sk);
  416. netlink_table_ungrab();
  417. kfree(nlk->groups);
  418. nlk->groups = NULL;
  419. sock_put(sk);
  420. return 0;
  421. }
  422. static int netlink_autobind(struct socket *sock)
  423. {
  424. struct sock *sk = sock->sk;
  425. struct net *net = sk->sk_net;
  426. struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash;
  427. struct hlist_head *head;
  428. struct sock *osk;
  429. struct hlist_node *node;
  430. s32 pid = current->tgid;
  431. int err;
  432. static s32 rover = -4097;
  433. retry:
  434. cond_resched();
  435. netlink_table_grab();
  436. head = nl_pid_hashfn(hash, pid);
  437. sk_for_each(osk, node, head) {
  438. if ((osk->sk_net != net))
  439. continue;
  440. if (nlk_sk(osk)->pid == pid) {
  441. /* Bind collision, search negative pid values. */
  442. pid = rover--;
  443. if (rover > -4097)
  444. rover = -4097;
  445. netlink_table_ungrab();
  446. goto retry;
  447. }
  448. }
  449. netlink_table_ungrab();
  450. err = netlink_insert(sk, net, pid);
  451. if (err == -EADDRINUSE)
  452. goto retry;
  453. /* If 2 threads race to autobind, that is fine. */
  454. if (err == -EBUSY)
  455. err = 0;
  456. return err;
  457. }
  458. static inline int netlink_capable(struct socket *sock, unsigned int flag)
  459. {
  460. return (nl_table[sock->sk->sk_protocol].nl_nonroot & flag) ||
  461. capable(CAP_NET_ADMIN);
  462. }
  463. static void
  464. netlink_update_subscriptions(struct sock *sk, unsigned int subscriptions)
  465. {
  466. struct netlink_sock *nlk = nlk_sk(sk);
  467. if (nlk->subscriptions && !subscriptions)
  468. __sk_del_bind_node(sk);
  469. else if (!nlk->subscriptions && subscriptions)
  470. sk_add_bind_node(sk, &nl_table[sk->sk_protocol].mc_list);
  471. nlk->subscriptions = subscriptions;
  472. }
  473. static int netlink_realloc_groups(struct sock *sk)
  474. {
  475. struct netlink_sock *nlk = nlk_sk(sk);
  476. unsigned int groups;
  477. unsigned long *new_groups;
  478. int err = 0;
  479. netlink_table_grab();
  480. groups = nl_table[sk->sk_protocol].groups;
  481. if (!nl_table[sk->sk_protocol].registered) {
  482. err = -ENOENT;
  483. goto out_unlock;
  484. }
  485. if (nlk->ngroups >= groups)
  486. goto out_unlock;
  487. new_groups = krealloc(nlk->groups, NLGRPSZ(groups), GFP_ATOMIC);
  488. if (new_groups == NULL) {
  489. err = -ENOMEM;
  490. goto out_unlock;
  491. }
  492. memset((char*)new_groups + NLGRPSZ(nlk->ngroups), 0,
  493. NLGRPSZ(groups) - NLGRPSZ(nlk->ngroups));
  494. nlk->groups = new_groups;
  495. nlk->ngroups = groups;
  496. out_unlock:
  497. netlink_table_ungrab();
  498. return err;
  499. }
  500. static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
  501. {
  502. struct sock *sk = sock->sk;
  503. struct net *net = sk->sk_net;
  504. struct netlink_sock *nlk = nlk_sk(sk);
  505. struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
  506. int err;
  507. if (nladdr->nl_family != AF_NETLINK)
  508. return -EINVAL;
  509. /* Only superuser is allowed to listen multicasts */
  510. if (nladdr->nl_groups) {
  511. if (!netlink_capable(sock, NL_NONROOT_RECV))
  512. return -EPERM;
  513. err = netlink_realloc_groups(sk);
  514. if (err)
  515. return err;
  516. }
  517. if (nlk->pid) {
  518. if (nladdr->nl_pid != nlk->pid)
  519. return -EINVAL;
  520. } else {
  521. err = nladdr->nl_pid ?
  522. netlink_insert(sk, net, nladdr->nl_pid) :
  523. netlink_autobind(sock);
  524. if (err)
  525. return err;
  526. }
  527. if (!nladdr->nl_groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
  528. return 0;
  529. netlink_table_grab();
  530. netlink_update_subscriptions(sk, nlk->subscriptions +
  531. hweight32(nladdr->nl_groups) -
  532. hweight32(nlk->groups[0]));
  533. nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | nladdr->nl_groups;
  534. netlink_update_listeners(sk);
  535. netlink_table_ungrab();
  536. return 0;
  537. }
  538. static int netlink_connect(struct socket *sock, struct sockaddr *addr,
  539. int alen, int flags)
  540. {
  541. int err = 0;
  542. struct sock *sk = sock->sk;
  543. struct netlink_sock *nlk = nlk_sk(sk);
  544. struct sockaddr_nl *nladdr=(struct sockaddr_nl*)addr;
  545. if (addr->sa_family == AF_UNSPEC) {
  546. sk->sk_state = NETLINK_UNCONNECTED;
  547. nlk->dst_pid = 0;
  548. nlk->dst_group = 0;
  549. return 0;
  550. }
  551. if (addr->sa_family != AF_NETLINK)
  552. return -EINVAL;
  553. /* Only superuser is allowed to send multicasts */
  554. if (nladdr->nl_groups && !netlink_capable(sock, NL_NONROOT_SEND))
  555. return -EPERM;
  556. if (!nlk->pid)
  557. err = netlink_autobind(sock);
  558. if (err == 0) {
  559. sk->sk_state = NETLINK_CONNECTED;
  560. nlk->dst_pid = nladdr->nl_pid;
  561. nlk->dst_group = ffs(nladdr->nl_groups);
  562. }
  563. return err;
  564. }
  565. static int netlink_getname(struct socket *sock, struct sockaddr *addr, int *addr_len, int peer)
  566. {
  567. struct sock *sk = sock->sk;
  568. struct netlink_sock *nlk = nlk_sk(sk);
  569. struct sockaddr_nl *nladdr=(struct sockaddr_nl *)addr;
  570. nladdr->nl_family = AF_NETLINK;
  571. nladdr->nl_pad = 0;
  572. *addr_len = sizeof(*nladdr);
  573. if (peer) {
  574. nladdr->nl_pid = nlk->dst_pid;
  575. nladdr->nl_groups = netlink_group_mask(nlk->dst_group);
  576. } else {
  577. nladdr->nl_pid = nlk->pid;
  578. nladdr->nl_groups = nlk->groups ? nlk->groups[0] : 0;
  579. }
  580. return 0;
  581. }
  582. static void netlink_overrun(struct sock *sk)
  583. {
  584. if (!test_and_set_bit(0, &nlk_sk(sk)->state)) {
  585. sk->sk_err = ENOBUFS;
  586. sk->sk_error_report(sk);
  587. }
  588. }
  589. static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
  590. {
  591. int protocol = ssk->sk_protocol;
  592. struct net *net;
  593. struct sock *sock;
  594. struct netlink_sock *nlk;
  595. net = ssk->sk_net;
  596. sock = netlink_lookup(net, protocol, pid);
  597. if (!sock)
  598. return ERR_PTR(-ECONNREFUSED);
  599. /* Don't bother queuing skb if kernel socket has no input function */
  600. nlk = nlk_sk(sock);
  601. if ((nlk->pid == 0 && !nlk->data_ready) ||
  602. (sock->sk_state == NETLINK_CONNECTED &&
  603. nlk->dst_pid != nlk_sk(ssk)->pid)) {
  604. sock_put(sock);
  605. return ERR_PTR(-ECONNREFUSED);
  606. }
  607. return sock;
  608. }
  609. struct sock *netlink_getsockbyfilp(struct file *filp)
  610. {
  611. struct inode *inode = filp->f_path.dentry->d_inode;
  612. struct sock *sock;
  613. if (!S_ISSOCK(inode->i_mode))
  614. return ERR_PTR(-ENOTSOCK);
  615. sock = SOCKET_I(inode)->sk;
  616. if (sock->sk_family != AF_NETLINK)
  617. return ERR_PTR(-EINVAL);
  618. sock_hold(sock);
  619. return sock;
  620. }
  621. /*
  622. * Attach a skb to a netlink socket.
  623. * The caller must hold a reference to the destination socket. On error, the
  624. * reference is dropped. The skb is not send to the destination, just all
  625. * all error checks are performed and memory in the queue is reserved.
  626. * Return values:
  627. * < 0: error. skb freed, reference to sock dropped.
  628. * 0: continue
  629. * 1: repeat lookup - reference dropped while waiting for socket memory.
  630. */
  631. int netlink_attachskb(struct sock *sk, struct sk_buff *skb, int nonblock,
  632. long timeo, struct sock *ssk)
  633. {
  634. struct netlink_sock *nlk;
  635. nlk = nlk_sk(sk);
  636. if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf ||
  637. test_bit(0, &nlk->state)) {
  638. DECLARE_WAITQUEUE(wait, current);
  639. if (!timeo) {
  640. if (!ssk || nlk_sk(ssk)->pid == 0)
  641. netlink_overrun(sk);
  642. sock_put(sk);
  643. kfree_skb(skb);
  644. return -EAGAIN;
  645. }
  646. __set_current_state(TASK_INTERRUPTIBLE);
  647. add_wait_queue(&nlk->wait, &wait);
  648. if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf ||
  649. test_bit(0, &nlk->state)) &&
  650. !sock_flag(sk, SOCK_DEAD))
  651. timeo = schedule_timeout(timeo);
  652. __set_current_state(TASK_RUNNING);
  653. remove_wait_queue(&nlk->wait, &wait);
  654. sock_put(sk);
  655. if (signal_pending(current)) {
  656. kfree_skb(skb);
  657. return sock_intr_errno(timeo);
  658. }
  659. return 1;
  660. }
  661. skb_set_owner_r(skb, sk);
  662. return 0;
  663. }
  664. int netlink_sendskb(struct sock *sk, struct sk_buff *skb, int protocol)
  665. {
  666. int len = skb->len;
  667. skb_queue_tail(&sk->sk_receive_queue, skb);
  668. sk->sk_data_ready(sk, len);
  669. sock_put(sk);
  670. return len;
  671. }
  672. void netlink_detachskb(struct sock *sk, struct sk_buff *skb)
  673. {
  674. kfree_skb(skb);
  675. sock_put(sk);
  676. }
  677. static inline struct sk_buff *netlink_trim(struct sk_buff *skb,
  678. gfp_t allocation)
  679. {
  680. int delta;
  681. skb_orphan(skb);
  682. delta = skb->end - skb->tail;
  683. if (delta * 2 < skb->truesize)
  684. return skb;
  685. if (skb_shared(skb)) {
  686. struct sk_buff *nskb = skb_clone(skb, allocation);
  687. if (!nskb)
  688. return skb;
  689. kfree_skb(skb);
  690. skb = nskb;
  691. }
  692. if (!pskb_expand_head(skb, 0, -delta, allocation))
  693. skb->truesize -= delta;
  694. return skb;
  695. }
  696. int netlink_unicast(struct sock *ssk, struct sk_buff *skb, u32 pid, int nonblock)
  697. {
  698. struct sock *sk;
  699. int err;
  700. long timeo;
  701. skb = netlink_trim(skb, gfp_any());
  702. timeo = sock_sndtimeo(ssk, nonblock);
  703. retry:
  704. sk = netlink_getsockbypid(ssk, pid);
  705. if (IS_ERR(sk)) {
  706. kfree_skb(skb);
  707. return PTR_ERR(sk);
  708. }
  709. err = netlink_attachskb(sk, skb, nonblock, timeo, ssk);
  710. if (err == 1)
  711. goto retry;
  712. if (err)
  713. return err;
  714. return netlink_sendskb(sk, skb, ssk->sk_protocol);
  715. }
  716. int netlink_has_listeners(struct sock *sk, unsigned int group)
  717. {
  718. int res = 0;
  719. unsigned long *listeners;
  720. BUG_ON(!(nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET));
  721. rcu_read_lock();
  722. listeners = rcu_dereference(nl_table[sk->sk_protocol].listeners);
  723. if (group - 1 < nl_table[sk->sk_protocol].groups)
  724. res = test_bit(group - 1, listeners);
  725. rcu_read_unlock();
  726. return res;
  727. }
  728. EXPORT_SYMBOL_GPL(netlink_has_listeners);
  729. static __inline__ int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
  730. {
  731. struct netlink_sock *nlk = nlk_sk(sk);
  732. if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
  733. !test_bit(0, &nlk->state)) {
  734. skb_set_owner_r(skb, sk);
  735. skb_queue_tail(&sk->sk_receive_queue, skb);
  736. sk->sk_data_ready(sk, skb->len);
  737. return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf;
  738. }
  739. return -1;
  740. }
  741. struct netlink_broadcast_data {
  742. struct sock *exclude_sk;
  743. struct net *net;
  744. u32 pid;
  745. u32 group;
  746. int failure;
  747. int congested;
  748. int delivered;
  749. gfp_t allocation;
  750. struct sk_buff *skb, *skb2;
  751. };
  752. static inline int do_one_broadcast(struct sock *sk,
  753. struct netlink_broadcast_data *p)
  754. {
  755. struct netlink_sock *nlk = nlk_sk(sk);
  756. int val;
  757. if (p->exclude_sk == sk)
  758. goto out;
  759. if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups ||
  760. !test_bit(p->group - 1, nlk->groups))
  761. goto out;
  762. if ((sk->sk_net != p->net))
  763. goto out;
  764. if (p->failure) {
  765. netlink_overrun(sk);
  766. goto out;
  767. }
  768. sock_hold(sk);
  769. if (p->skb2 == NULL) {
  770. if (skb_shared(p->skb)) {
  771. p->skb2 = skb_clone(p->skb, p->allocation);
  772. } else {
  773. p->skb2 = skb_get(p->skb);
  774. /*
  775. * skb ownership may have been set when
  776. * delivered to a previous socket.
  777. */
  778. skb_orphan(p->skb2);
  779. }
  780. }
  781. if (p->skb2 == NULL) {
  782. netlink_overrun(sk);
  783. /* Clone failed. Notify ALL listeners. */
  784. p->failure = 1;
  785. } else if ((val = netlink_broadcast_deliver(sk, p->skb2)) < 0) {
  786. netlink_overrun(sk);
  787. } else {
  788. p->congested |= val;
  789. p->delivered = 1;
  790. p->skb2 = NULL;
  791. }
  792. sock_put(sk);
  793. out:
  794. return 0;
  795. }
  796. int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid,
  797. u32 group, gfp_t allocation)
  798. {
  799. struct net *net = ssk->sk_net;
  800. struct netlink_broadcast_data info;
  801. struct hlist_node *node;
  802. struct sock *sk;
  803. skb = netlink_trim(skb, allocation);
  804. info.exclude_sk = ssk;
  805. info.net = net;
  806. info.pid = pid;
  807. info.group = group;
  808. info.failure = 0;
  809. info.congested = 0;
  810. info.delivered = 0;
  811. info.allocation = allocation;
  812. info.skb = skb;
  813. info.skb2 = NULL;
  814. /* While we sleep in clone, do not allow to change socket list */
  815. netlink_lock_table();
  816. sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list)
  817. do_one_broadcast(sk, &info);
  818. kfree_skb(skb);
  819. netlink_unlock_table();
  820. if (info.skb2)
  821. kfree_skb(info.skb2);
  822. if (info.delivered) {
  823. if (info.congested && (allocation & __GFP_WAIT))
  824. yield();
  825. return 0;
  826. }
  827. if (info.failure)
  828. return -ENOBUFS;
  829. return -ESRCH;
  830. }
  831. struct netlink_set_err_data {
  832. struct sock *exclude_sk;
  833. u32 pid;
  834. u32 group;
  835. int code;
  836. };
  837. static inline int do_one_set_err(struct sock *sk,
  838. struct netlink_set_err_data *p)
  839. {
  840. struct netlink_sock *nlk = nlk_sk(sk);
  841. if (sk == p->exclude_sk)
  842. goto out;
  843. if (sk->sk_net != p->exclude_sk->sk_net)
  844. goto out;
  845. if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups ||
  846. !test_bit(p->group - 1, nlk->groups))
  847. goto out;
  848. sk->sk_err = p->code;
  849. sk->sk_error_report(sk);
  850. out:
  851. return 0;
  852. }
  853. void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
  854. {
  855. struct netlink_set_err_data info;
  856. struct hlist_node *node;
  857. struct sock *sk;
  858. info.exclude_sk = ssk;
  859. info.pid = pid;
  860. info.group = group;
  861. info.code = code;
  862. read_lock(&nl_table_lock);
  863. sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list)
  864. do_one_set_err(sk, &info);
  865. read_unlock(&nl_table_lock);
  866. }
  867. /* must be called with netlink table grabbed */
  868. static void netlink_update_socket_mc(struct netlink_sock *nlk,
  869. unsigned int group,
  870. int is_new)
  871. {
  872. int old, new = !!is_new, subscriptions;
  873. old = test_bit(group - 1, nlk->groups);
  874. subscriptions = nlk->subscriptions - old + new;
  875. if (new)
  876. __set_bit(group - 1, nlk->groups);
  877. else
  878. __clear_bit(group - 1, nlk->groups);
  879. netlink_update_subscriptions(&nlk->sk, subscriptions);
  880. netlink_update_listeners(&nlk->sk);
  881. }
  882. static int netlink_setsockopt(struct socket *sock, int level, int optname,
  883. char __user *optval, int optlen)
  884. {
  885. struct sock *sk = sock->sk;
  886. struct netlink_sock *nlk = nlk_sk(sk);
  887. unsigned int val = 0;
  888. int err;
  889. if (level != SOL_NETLINK)
  890. return -ENOPROTOOPT;
  891. if (optlen >= sizeof(int) &&
  892. get_user(val, (unsigned int __user *)optval))
  893. return -EFAULT;
  894. switch (optname) {
  895. case NETLINK_PKTINFO:
  896. if (val)
  897. nlk->flags |= NETLINK_RECV_PKTINFO;
  898. else
  899. nlk->flags &= ~NETLINK_RECV_PKTINFO;
  900. err = 0;
  901. break;
  902. case NETLINK_ADD_MEMBERSHIP:
  903. case NETLINK_DROP_MEMBERSHIP: {
  904. if (!netlink_capable(sock, NL_NONROOT_RECV))
  905. return -EPERM;
  906. err = netlink_realloc_groups(sk);
  907. if (err)
  908. return err;
  909. if (!val || val - 1 >= nlk->ngroups)
  910. return -EINVAL;
  911. netlink_table_grab();
  912. netlink_update_socket_mc(nlk, val,
  913. optname == NETLINK_ADD_MEMBERSHIP);
  914. netlink_table_ungrab();
  915. err = 0;
  916. break;
  917. }
  918. default:
  919. err = -ENOPROTOOPT;
  920. }
  921. return err;
  922. }
  923. static int netlink_getsockopt(struct socket *sock, int level, int optname,
  924. char __user *optval, int __user *optlen)
  925. {
  926. struct sock *sk = sock->sk;
  927. struct netlink_sock *nlk = nlk_sk(sk);
  928. int len, val, err;
  929. if (level != SOL_NETLINK)
  930. return -ENOPROTOOPT;
  931. if (get_user(len, optlen))
  932. return -EFAULT;
  933. if (len < 0)
  934. return -EINVAL;
  935. switch (optname) {
  936. case NETLINK_PKTINFO:
  937. if (len < sizeof(int))
  938. return -EINVAL;
  939. len = sizeof(int);
  940. val = nlk->flags & NETLINK_RECV_PKTINFO ? 1 : 0;
  941. if (put_user(len, optlen) ||
  942. put_user(val, optval))
  943. return -EFAULT;
  944. err = 0;
  945. break;
  946. default:
  947. err = -ENOPROTOOPT;
  948. }
  949. return err;
  950. }
  951. static void netlink_cmsg_recv_pktinfo(struct msghdr *msg, struct sk_buff *skb)
  952. {
  953. struct nl_pktinfo info;
  954. info.group = NETLINK_CB(skb).dst_group;
  955. put_cmsg(msg, SOL_NETLINK, NETLINK_PKTINFO, sizeof(info), &info);
  956. }
  957. static inline void netlink_rcv_wake(struct sock *sk)
  958. {
  959. struct netlink_sock *nlk = nlk_sk(sk);
  960. if (skb_queue_empty(&sk->sk_receive_queue))
  961. clear_bit(0, &nlk->state);
  962. if (!test_bit(0, &nlk->state))
  963. wake_up_interruptible(&nlk->wait);
  964. }
  965. static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
  966. struct msghdr *msg, size_t len)
  967. {
  968. struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
  969. struct sock *sk = sock->sk;
  970. struct netlink_sock *nlk = nlk_sk(sk);
  971. struct sockaddr_nl *addr=msg->msg_name;
  972. u32 dst_pid;
  973. u32 dst_group;
  974. struct sk_buff *skb;
  975. int err;
  976. struct scm_cookie scm;
  977. if (msg->msg_flags&MSG_OOB)
  978. return -EOPNOTSUPP;
  979. if (NULL == siocb->scm)
  980. siocb->scm = &scm;
  981. err = scm_send(sock, msg, siocb->scm);
  982. if (err < 0)
  983. return err;
  984. if (msg->msg_namelen) {
  985. if (addr->nl_family != AF_NETLINK)
  986. return -EINVAL;
  987. dst_pid = addr->nl_pid;
  988. dst_group = ffs(addr->nl_groups);
  989. if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND))
  990. return -EPERM;
  991. } else {
  992. dst_pid = nlk->dst_pid;
  993. dst_group = nlk->dst_group;
  994. }
  995. if (!nlk->pid) {
  996. err = netlink_autobind(sock);
  997. if (err)
  998. goto out;
  999. }
  1000. err = -EMSGSIZE;
  1001. if (len > sk->sk_sndbuf - 32)
  1002. goto out;
  1003. err = -ENOBUFS;
  1004. skb = alloc_skb(len, GFP_KERNEL);
  1005. if (skb==NULL)
  1006. goto out;
  1007. NETLINK_CB(skb).pid = nlk->pid;
  1008. NETLINK_CB(skb).dst_group = dst_group;
  1009. NETLINK_CB(skb).loginuid = audit_get_loginuid(current->audit_context);
  1010. selinux_get_task_sid(current, &(NETLINK_CB(skb).sid));
  1011. memcpy(NETLINK_CREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
  1012. /* What can I do? Netlink is asynchronous, so that
  1013. we will have to save current capabilities to
  1014. check them, when this message will be delivered
  1015. to corresponding kernel module. --ANK (980802)
  1016. */
  1017. err = -EFAULT;
  1018. if (memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len)) {
  1019. kfree_skb(skb);
  1020. goto out;
  1021. }
  1022. err = security_netlink_send(sk, skb);
  1023. if (err) {
  1024. kfree_skb(skb);
  1025. goto out;
  1026. }
  1027. if (dst_group) {
  1028. atomic_inc(&skb->users);
  1029. netlink_broadcast(sk, skb, dst_pid, dst_group, GFP_KERNEL);
  1030. }
  1031. err = netlink_unicast(sk, skb, dst_pid, msg->msg_flags&MSG_DONTWAIT);
  1032. out:
  1033. return err;
  1034. }
  1035. static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
  1036. struct msghdr *msg, size_t len,
  1037. int flags)
  1038. {
  1039. struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
  1040. struct scm_cookie scm;
  1041. struct sock *sk = sock->sk;
  1042. struct netlink_sock *nlk = nlk_sk(sk);
  1043. int noblock = flags&MSG_DONTWAIT;
  1044. size_t copied;
  1045. struct sk_buff *skb;
  1046. int err;
  1047. if (flags&MSG_OOB)
  1048. return -EOPNOTSUPP;
  1049. copied = 0;
  1050. skb = skb_recv_datagram(sk,flags,noblock,&err);
  1051. if (skb==NULL)
  1052. goto out;
  1053. msg->msg_namelen = 0;
  1054. copied = skb->len;
  1055. if (len < copied) {
  1056. msg->msg_flags |= MSG_TRUNC;
  1057. copied = len;
  1058. }
  1059. skb_reset_transport_header(skb);
  1060. err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
  1061. if (msg->msg_name) {
  1062. struct sockaddr_nl *addr = (struct sockaddr_nl*)msg->msg_name;
  1063. addr->nl_family = AF_NETLINK;
  1064. addr->nl_pad = 0;
  1065. addr->nl_pid = NETLINK_CB(skb).pid;
  1066. addr->nl_groups = netlink_group_mask(NETLINK_CB(skb).dst_group);
  1067. msg->msg_namelen = sizeof(*addr);
  1068. }
  1069. if (nlk->flags & NETLINK_RECV_PKTINFO)
  1070. netlink_cmsg_recv_pktinfo(msg, skb);
  1071. if (NULL == siocb->scm) {
  1072. memset(&scm, 0, sizeof(scm));
  1073. siocb->scm = &scm;
  1074. }
  1075. siocb->scm->creds = *NETLINK_CREDS(skb);
  1076. if (flags & MSG_TRUNC)
  1077. copied = skb->len;
  1078. skb_free_datagram(sk, skb);
  1079. if (nlk->cb && atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf / 2)
  1080. netlink_dump(sk);
  1081. scm_recv(sock, msg, siocb->scm, flags);
  1082. out:
  1083. netlink_rcv_wake(sk);
  1084. return err ? : copied;
  1085. }
  1086. static void netlink_data_ready(struct sock *sk, int len)
  1087. {
  1088. struct netlink_sock *nlk = nlk_sk(sk);
  1089. if (nlk->data_ready)
  1090. nlk->data_ready(sk, len);
  1091. netlink_rcv_wake(sk);
  1092. }
  1093. /*
  1094. * We export these functions to other modules. They provide a
  1095. * complete set of kernel non-blocking support for message
  1096. * queueing.
  1097. */
  1098. struct sock *
  1099. netlink_kernel_create(struct net *net, int unit, unsigned int groups,
  1100. void (*input)(struct sock *sk, int len),
  1101. struct mutex *cb_mutex, struct module *module)
  1102. {
  1103. struct socket *sock;
  1104. struct sock *sk;
  1105. struct netlink_sock *nlk;
  1106. unsigned long *listeners = NULL;
  1107. BUG_ON(!nl_table);
  1108. if (unit<0 || unit>=MAX_LINKS)
  1109. return NULL;
  1110. if (sock_create_lite(PF_NETLINK, SOCK_DGRAM, unit, &sock))
  1111. return NULL;
  1112. if (__netlink_create(net, sock, cb_mutex, unit) < 0)
  1113. goto out_sock_release;
  1114. if (groups < 32)
  1115. groups = 32;
  1116. listeners = kzalloc(NLGRPSZ(groups), GFP_KERNEL);
  1117. if (!listeners)
  1118. goto out_sock_release;
  1119. sk = sock->sk;
  1120. sk->sk_data_ready = netlink_data_ready;
  1121. if (input)
  1122. nlk_sk(sk)->data_ready = input;
  1123. if (netlink_insert(sk, net, 0))
  1124. goto out_sock_release;
  1125. nlk = nlk_sk(sk);
  1126. nlk->flags |= NETLINK_KERNEL_SOCKET;
  1127. netlink_table_grab();
  1128. if (!nl_table[unit].registered) {
  1129. nl_table[unit].groups = groups;
  1130. nl_table[unit].listeners = listeners;
  1131. nl_table[unit].cb_mutex = cb_mutex;
  1132. nl_table[unit].module = module;
  1133. nl_table[unit].registered = 1;
  1134. }
  1135. netlink_table_ungrab();
  1136. return sk;
  1137. out_sock_release:
  1138. kfree(listeners);
  1139. sock_release(sock);
  1140. return NULL;
  1141. }
  1142. /**
  1143. * netlink_change_ngroups - change number of multicast groups
  1144. *
  1145. * This changes the number of multicast groups that are available
  1146. * on a certain netlink family. Note that it is not possible to
  1147. * change the number of groups to below 32. Also note that it does
  1148. * not implicitly call netlink_clear_multicast_users() when the
  1149. * number of groups is reduced.
  1150. *
  1151. * @sk: The kernel netlink socket, as returned by netlink_kernel_create().
  1152. * @groups: The new number of groups.
  1153. */
  1154. int netlink_change_ngroups(struct sock *sk, unsigned int groups)
  1155. {
  1156. unsigned long *listeners, *old = NULL;
  1157. struct netlink_table *tbl = &nl_table[sk->sk_protocol];
  1158. int err = 0;
  1159. if (groups < 32)
  1160. groups = 32;
  1161. netlink_table_grab();
  1162. if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) {
  1163. listeners = kzalloc(NLGRPSZ(groups), GFP_ATOMIC);
  1164. if (!listeners) {
  1165. err = -ENOMEM;
  1166. goto out_ungrab;
  1167. }
  1168. old = tbl->listeners;
  1169. memcpy(listeners, old, NLGRPSZ(tbl->groups));
  1170. rcu_assign_pointer(tbl->listeners, listeners);
  1171. }
  1172. tbl->groups = groups;
  1173. out_ungrab:
  1174. netlink_table_ungrab();
  1175. synchronize_rcu();
  1176. kfree(old);
  1177. return err;
  1178. }
  1179. EXPORT_SYMBOL(netlink_change_ngroups);
  1180. /**
  1181. * netlink_clear_multicast_users - kick off multicast listeners
  1182. *
  1183. * This function removes all listeners from the given group.
  1184. * @ksk: The kernel netlink socket, as returned by
  1185. * netlink_kernel_create().
  1186. * @group: The multicast group to clear.
  1187. */
  1188. void netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
  1189. {
  1190. struct sock *sk;
  1191. struct hlist_node *node;
  1192. struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
  1193. netlink_table_grab();
  1194. sk_for_each_bound(sk, node, &tbl->mc_list)
  1195. netlink_update_socket_mc(nlk_sk(sk), group, 0);
  1196. netlink_table_ungrab();
  1197. }
  1198. EXPORT_SYMBOL(netlink_clear_multicast_users);
  1199. void netlink_set_nonroot(int protocol, unsigned int flags)
  1200. {
  1201. if ((unsigned int)protocol < MAX_LINKS)
  1202. nl_table[protocol].nl_nonroot = flags;
  1203. }
  1204. static void netlink_destroy_callback(struct netlink_callback *cb)
  1205. {
  1206. if (cb->skb)
  1207. kfree_skb(cb->skb);
  1208. kfree(cb);
  1209. }
  1210. /*
  1211. * It looks a bit ugly.
  1212. * It would be better to create kernel thread.
  1213. */
  1214. static int netlink_dump(struct sock *sk)
  1215. {
  1216. struct netlink_sock *nlk = nlk_sk(sk);
  1217. struct netlink_callback *cb;
  1218. struct sk_buff *skb;
  1219. struct nlmsghdr *nlh;
  1220. int len, err = -ENOBUFS;
  1221. skb = sock_rmalloc(sk, NLMSG_GOODSIZE, 0, GFP_KERNEL);
  1222. if (!skb)
  1223. goto errout;
  1224. mutex_lock(nlk->cb_mutex);
  1225. cb = nlk->cb;
  1226. if (cb == NULL) {
  1227. err = -EINVAL;
  1228. goto errout_skb;
  1229. }
  1230. len = cb->dump(skb, cb);
  1231. if (len > 0) {
  1232. mutex_unlock(nlk->cb_mutex);
  1233. skb_queue_tail(&sk->sk_receive_queue, skb);
  1234. sk->sk_data_ready(sk, len);
  1235. return 0;
  1236. }
  1237. nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
  1238. if (!nlh)
  1239. goto errout_skb;
  1240. memcpy(nlmsg_data(nlh), &len, sizeof(len));
  1241. skb_queue_tail(&sk->sk_receive_queue, skb);
  1242. sk->sk_data_ready(sk, skb->len);
  1243. if (cb->done)
  1244. cb->done(cb);
  1245. nlk->cb = NULL;
  1246. mutex_unlock(nlk->cb_mutex);
  1247. netlink_destroy_callback(cb);
  1248. return 0;
  1249. errout_skb:
  1250. mutex_unlock(nlk->cb_mutex);
  1251. kfree_skb(skb);
  1252. errout:
  1253. return err;
  1254. }
  1255. int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
  1256. struct nlmsghdr *nlh,
  1257. int (*dump)(struct sk_buff *skb, struct netlink_callback*),
  1258. int (*done)(struct netlink_callback*))
  1259. {
  1260. struct netlink_callback *cb;
  1261. struct sock *sk;
  1262. struct netlink_sock *nlk;
  1263. cb = kzalloc(sizeof(*cb), GFP_KERNEL);
  1264. if (cb == NULL)
  1265. return -ENOBUFS;
  1266. cb->dump = dump;
  1267. cb->done = done;
  1268. cb->nlh = nlh;
  1269. atomic_inc(&skb->users);
  1270. cb->skb = skb;
  1271. sk = netlink_lookup(ssk->sk_net, ssk->sk_protocol, NETLINK_CB(skb).pid);
  1272. if (sk == NULL) {
  1273. netlink_destroy_callback(cb);
  1274. return -ECONNREFUSED;
  1275. }
  1276. nlk = nlk_sk(sk);
  1277. /* A dump is in progress... */
  1278. mutex_lock(nlk->cb_mutex);
  1279. if (nlk->cb) {
  1280. mutex_unlock(nlk->cb_mutex);
  1281. netlink_destroy_callback(cb);
  1282. sock_put(sk);
  1283. return -EBUSY;
  1284. }
  1285. nlk->cb = cb;
  1286. mutex_unlock(nlk->cb_mutex);
  1287. netlink_dump(sk);
  1288. sock_put(sk);
  1289. /* We successfully started a dump, by returning -EINTR we
  1290. * signal the queue mangement to interrupt processing of
  1291. * any netlink messages so userspace gets a chance to read
  1292. * the results. */
  1293. return -EINTR;
  1294. }
  1295. void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
  1296. {
  1297. struct sk_buff *skb;
  1298. struct nlmsghdr *rep;
  1299. struct nlmsgerr *errmsg;
  1300. size_t payload = sizeof(*errmsg);
  1301. /* error messages get the original request appened */
  1302. if (err)
  1303. payload += nlmsg_len(nlh);
  1304. skb = nlmsg_new(payload, GFP_KERNEL);
  1305. if (!skb) {
  1306. struct sock *sk;
  1307. sk = netlink_lookup(in_skb->sk->sk_net,
  1308. in_skb->sk->sk_protocol,
  1309. NETLINK_CB(in_skb).pid);
  1310. if (sk) {
  1311. sk->sk_err = ENOBUFS;
  1312. sk->sk_error_report(sk);
  1313. sock_put(sk);
  1314. }
  1315. return;
  1316. }
  1317. rep = __nlmsg_put(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq,
  1318. NLMSG_ERROR, sizeof(struct nlmsgerr), 0);
  1319. errmsg = nlmsg_data(rep);
  1320. errmsg->error = err;
  1321. memcpy(&errmsg->msg, nlh, err ? nlh->nlmsg_len : sizeof(*nlh));
  1322. netlink_unicast(in_skb->sk, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
  1323. }
  1324. static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
  1325. struct nlmsghdr *))
  1326. {
  1327. struct nlmsghdr *nlh;
  1328. int err;
  1329. while (skb->len >= nlmsg_total_size(0)) {
  1330. nlh = nlmsg_hdr(skb);
  1331. err = 0;
  1332. if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
  1333. return 0;
  1334. /* Only requests are handled by the kernel */
  1335. if (!(nlh->nlmsg_flags & NLM_F_REQUEST))
  1336. goto skip;
  1337. /* Skip control messages */
  1338. if (nlh->nlmsg_type < NLMSG_MIN_TYPE)
  1339. goto skip;
  1340. err = cb(skb, nlh);
  1341. if (err == -EINTR) {
  1342. /* Not an error, but we interrupt processing */
  1343. netlink_queue_skip(nlh, skb);
  1344. return err;
  1345. }
  1346. skip:
  1347. if (nlh->nlmsg_flags & NLM_F_ACK || err)
  1348. netlink_ack(skb, nlh, err);
  1349. netlink_queue_skip(nlh, skb);
  1350. }
  1351. return 0;
  1352. }
  1353. /**
  1354. * nelink_run_queue - Process netlink receive queue.
  1355. * @sk: Netlink socket containing the queue
  1356. * @qlen: Initial queue length
  1357. * @cb: Callback function invoked for each netlink message found
  1358. *
  1359. * Processes as much as there was in the queue upon entry and invokes
  1360. * a callback function for each netlink message found. The callback
  1361. * function may refuse a message by returning a negative error code
  1362. * but setting the error pointer to 0 in which case this function
  1363. * returns with a qlen != 0.
  1364. *
  1365. * qlen must be initialized to 0 before the initial entry, afterwards
  1366. * the function may be called repeatedly until the returned qlen is 0.
  1367. *
  1368. * The callback function may return -EINTR to signal that processing
  1369. * of netlink messages shall be interrupted. In this case the message
  1370. * currently being processed will NOT be requeued onto the receive
  1371. * queue.
  1372. */
  1373. unsigned int netlink_run_queue(struct sock *sk, unsigned int qlen,
  1374. int (*cb)(struct sk_buff *, struct nlmsghdr *))
  1375. {
  1376. struct sk_buff *skb;
  1377. if (!qlen || qlen > skb_queue_len(&sk->sk_receive_queue))
  1378. qlen = skb_queue_len(&sk->sk_receive_queue);
  1379. for (; qlen; qlen--) {
  1380. skb = skb_dequeue(&sk->sk_receive_queue);
  1381. if (netlink_rcv_skb(skb, cb)) {
  1382. if (skb->len)
  1383. skb_queue_head(&sk->sk_receive_queue, skb);
  1384. else {
  1385. kfree_skb(skb);
  1386. qlen--;
  1387. }
  1388. break;
  1389. }
  1390. kfree_skb(skb);
  1391. }
  1392. return qlen;
  1393. }
  1394. /**
  1395. * netlink_queue_skip - Skip netlink message while processing queue.
  1396. * @nlh: Netlink message to be skipped
  1397. * @skb: Socket buffer containing the netlink messages.
  1398. *
  1399. * Pulls the given netlink message off the socket buffer so the next
  1400. * call to netlink_queue_run() will not reconsider the message.
  1401. */
  1402. static void netlink_queue_skip(struct nlmsghdr *nlh, struct sk_buff *skb)
  1403. {
  1404. int msglen = NLMSG_ALIGN(nlh->nlmsg_len);
  1405. if (msglen > skb->len)
  1406. msglen = skb->len;
  1407. skb_pull(skb, msglen);
  1408. }
  1409. /**
  1410. * nlmsg_notify - send a notification netlink message
  1411. * @sk: netlink socket to use
  1412. * @skb: notification message
  1413. * @pid: destination netlink pid for reports or 0
  1414. * @group: destination multicast group or 0
  1415. * @report: 1 to report back, 0 to disable
  1416. * @flags: allocation flags
  1417. */
  1418. int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 pid,
  1419. unsigned int group, int report, gfp_t flags)
  1420. {
  1421. int err = 0;
  1422. if (group) {
  1423. int exclude_pid = 0;
  1424. if (report) {
  1425. atomic_inc(&skb->users);
  1426. exclude_pid = pid;
  1427. }
  1428. /* errors reported via destination sk->sk_err */
  1429. nlmsg_multicast(sk, skb, exclude_pid, group, flags);
  1430. }
  1431. if (report)
  1432. err = nlmsg_unicast(sk, skb, pid);
  1433. return err;
  1434. }
  1435. #ifdef CONFIG_PROC_FS
  1436. struct nl_seq_iter {
  1437. struct net *net;
  1438. int link;
  1439. int hash_idx;
  1440. };
  1441. static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
  1442. {
  1443. struct nl_seq_iter *iter = seq->private;
  1444. int i, j;
  1445. struct sock *s;
  1446. struct hlist_node *node;
  1447. loff_t off = 0;
  1448. for (i=0; i<MAX_LINKS; i++) {
  1449. struct nl_pid_hash *hash = &nl_table[i].hash;
  1450. for (j = 0; j <= hash->mask; j++) {
  1451. sk_for_each(s, node, &hash->table[j]) {
  1452. if (iter->net != s->sk_net)
  1453. continue;
  1454. if (off == pos) {
  1455. iter->link = i;
  1456. iter->hash_idx = j;
  1457. return s;
  1458. }
  1459. ++off;
  1460. }
  1461. }
  1462. }
  1463. return NULL;
  1464. }
  1465. static void *netlink_seq_start(struct seq_file *seq, loff_t *pos)
  1466. {
  1467. read_lock(&nl_table_lock);
  1468. return *pos ? netlink_seq_socket_idx(seq, *pos - 1) : SEQ_START_TOKEN;
  1469. }
  1470. static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1471. {
  1472. struct sock *s;
  1473. struct nl_seq_iter *iter;
  1474. int i, j;
  1475. ++*pos;
  1476. if (v == SEQ_START_TOKEN)
  1477. return netlink_seq_socket_idx(seq, 0);
  1478. iter = seq->private;
  1479. s = v;
  1480. do {
  1481. s = sk_next(s);
  1482. } while (s && (iter->net != s->sk_net));
  1483. if (s)
  1484. return s;
  1485. i = iter->link;
  1486. j = iter->hash_idx + 1;
  1487. do {
  1488. struct nl_pid_hash *hash = &nl_table[i].hash;
  1489. for (; j <= hash->mask; j++) {
  1490. s = sk_head(&hash->table[j]);
  1491. while (s && (iter->net != s->sk_net))
  1492. s = sk_next(s);
  1493. if (s) {
  1494. iter->link = i;
  1495. iter->hash_idx = j;
  1496. return s;
  1497. }
  1498. }
  1499. j = 0;
  1500. } while (++i < MAX_LINKS);
  1501. return NULL;
  1502. }
  1503. static void netlink_seq_stop(struct seq_file *seq, void *v)
  1504. {
  1505. read_unlock(&nl_table_lock);
  1506. }
  1507. static int netlink_seq_show(struct seq_file *seq, void *v)
  1508. {
  1509. if (v == SEQ_START_TOKEN)
  1510. seq_puts(seq,
  1511. "sk Eth Pid Groups "
  1512. "Rmem Wmem Dump Locks\n");
  1513. else {
  1514. struct sock *s = v;
  1515. struct netlink_sock *nlk = nlk_sk(s);
  1516. seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %d\n",
  1517. s,
  1518. s->sk_protocol,
  1519. nlk->pid,
  1520. nlk->groups ? (u32)nlk->groups[0] : 0,
  1521. atomic_read(&s->sk_rmem_alloc),
  1522. atomic_read(&s->sk_wmem_alloc),
  1523. nlk->cb,
  1524. atomic_read(&s->sk_refcnt)
  1525. );
  1526. }
  1527. return 0;
  1528. }
  1529. static const struct seq_operations netlink_seq_ops = {
  1530. .start = netlink_seq_start,
  1531. .next = netlink_seq_next,
  1532. .stop = netlink_seq_stop,
  1533. .show = netlink_seq_show,
  1534. };
  1535. static int netlink_seq_open(struct inode *inode, struct file *file)
  1536. {
  1537. struct seq_file *seq;
  1538. struct nl_seq_iter *iter;
  1539. int err;
  1540. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  1541. if (!iter)
  1542. return -ENOMEM;
  1543. err = seq_open(file, &netlink_seq_ops);
  1544. if (err) {
  1545. kfree(iter);
  1546. return err;
  1547. }
  1548. seq = file->private_data;
  1549. seq->private = iter;
  1550. iter->net = get_proc_net(inode);
  1551. if (!iter->net) {
  1552. seq_release_private(inode, file);
  1553. return -ENXIO;
  1554. }
  1555. return 0;
  1556. }
  1557. static int netlink_seq_release(struct inode *inode, struct file *file)
  1558. {
  1559. struct seq_file *seq = file->private_data;
  1560. struct nl_seq_iter *iter = seq->private;
  1561. put_net(iter->net);
  1562. return seq_release_private(inode, file);
  1563. }
  1564. static const struct file_operations netlink_seq_fops = {
  1565. .owner = THIS_MODULE,
  1566. .open = netlink_seq_open,
  1567. .read = seq_read,
  1568. .llseek = seq_lseek,
  1569. .release = netlink_seq_release,
  1570. };
  1571. #endif
  1572. int netlink_register_notifier(struct notifier_block *nb)
  1573. {
  1574. return atomic_notifier_chain_register(&netlink_chain, nb);
  1575. }
  1576. int netlink_unregister_notifier(struct notifier_block *nb)
  1577. {
  1578. return atomic_notifier_chain_unregister(&netlink_chain, nb);
  1579. }
  1580. static const struct proto_ops netlink_ops = {
  1581. .family = PF_NETLINK,
  1582. .owner = THIS_MODULE,
  1583. .release = netlink_release,
  1584. .bind = netlink_bind,
  1585. .connect = netlink_connect,
  1586. .socketpair = sock_no_socketpair,
  1587. .accept = sock_no_accept,
  1588. .getname = netlink_getname,
  1589. .poll = datagram_poll,
  1590. .ioctl = sock_no_ioctl,
  1591. .listen = sock_no_listen,
  1592. .shutdown = sock_no_shutdown,
  1593. .setsockopt = netlink_setsockopt,
  1594. .getsockopt = netlink_getsockopt,
  1595. .sendmsg = netlink_sendmsg,
  1596. .recvmsg = netlink_recvmsg,
  1597. .mmap = sock_no_mmap,
  1598. .sendpage = sock_no_sendpage,
  1599. };
  1600. static struct net_proto_family netlink_family_ops = {
  1601. .family = PF_NETLINK,
  1602. .create = netlink_create,
  1603. .owner = THIS_MODULE, /* for consistency 8) */
  1604. };
  1605. static int netlink_net_init(struct net *net)
  1606. {
  1607. #ifdef CONFIG_PROC_FS
  1608. if (!proc_net_fops_create(net, "netlink", 0, &netlink_seq_fops))
  1609. return -ENOMEM;
  1610. #endif
  1611. return 0;
  1612. }
  1613. static void netlink_net_exit(struct net *net)
  1614. {
  1615. #ifdef CONFIG_PROC_FS
  1616. proc_net_remove(net, "netlink");
  1617. #endif
  1618. }
  1619. static struct pernet_operations netlink_net_ops = {
  1620. .init = netlink_net_init,
  1621. .exit = netlink_net_exit,
  1622. };
  1623. static int __init netlink_proto_init(void)
  1624. {
  1625. struct sk_buff *dummy_skb;
  1626. int i;
  1627. unsigned long limit;
  1628. unsigned int order;
  1629. int err = proto_register(&netlink_proto, 0);
  1630. if (err != 0)
  1631. goto out;
  1632. BUILD_BUG_ON(sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb));
  1633. nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL);
  1634. if (!nl_table)
  1635. goto panic;
  1636. if (num_physpages >= (128 * 1024))
  1637. limit = num_physpages >> (21 - PAGE_SHIFT);
  1638. else
  1639. limit = num_physpages >> (23 - PAGE_SHIFT);
  1640. order = get_bitmask_order(limit) - 1 + PAGE_SHIFT;
  1641. limit = (1UL << order) / sizeof(struct hlist_head);
  1642. order = get_bitmask_order(min(limit, (unsigned long)UINT_MAX)) - 1;
  1643. for (i = 0; i < MAX_LINKS; i++) {
  1644. struct nl_pid_hash *hash = &nl_table[i].hash;
  1645. hash->table = nl_pid_hash_alloc(1 * sizeof(*hash->table));
  1646. if (!hash->table) {
  1647. while (i-- > 0)
  1648. nl_pid_hash_free(nl_table[i].hash.table,
  1649. 1 * sizeof(*hash->table));
  1650. kfree(nl_table);
  1651. goto panic;
  1652. }
  1653. memset(hash->table, 0, 1 * sizeof(*hash->table));
  1654. hash->max_shift = order;
  1655. hash->shift = 0;
  1656. hash->mask = 0;
  1657. hash->rehash_time = jiffies;
  1658. }
  1659. sock_register(&netlink_family_ops);
  1660. register_pernet_subsys(&netlink_net_ops);
  1661. /* The netlink device handler may be needed early. */
  1662. rtnetlink_init();
  1663. out:
  1664. return err;
  1665. panic:
  1666. panic("netlink_init: Cannot allocate nl_table\n");
  1667. }
  1668. core_initcall(netlink_proto_init);
  1669. EXPORT_SYMBOL(netlink_ack);
  1670. EXPORT_SYMBOL(netlink_run_queue);
  1671. EXPORT_SYMBOL(netlink_broadcast);
  1672. EXPORT_SYMBOL(netlink_dump_start);
  1673. EXPORT_SYMBOL(netlink_kernel_create);
  1674. EXPORT_SYMBOL(netlink_register_notifier);
  1675. EXPORT_SYMBOL(netlink_set_nonroot);
  1676. EXPORT_SYMBOL(netlink_unicast);
  1677. EXPORT_SYMBOL(netlink_unregister_notifier);
  1678. EXPORT_SYMBOL(nlmsg_notify);