af_netlink.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  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: Place to store queue length upon entry
  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 qlen reaches 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. void 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. }
  1393. /**
  1394. * netlink_queue_skip - Skip netlink message while processing queue.
  1395. * @nlh: Netlink message to be skipped
  1396. * @skb: Socket buffer containing the netlink messages.
  1397. *
  1398. * Pulls the given netlink message off the socket buffer so the next
  1399. * call to netlink_queue_run() will not reconsider the message.
  1400. */
  1401. static void netlink_queue_skip(struct nlmsghdr *nlh, struct sk_buff *skb)
  1402. {
  1403. int msglen = NLMSG_ALIGN(nlh->nlmsg_len);
  1404. if (msglen > skb->len)
  1405. msglen = skb->len;
  1406. skb_pull(skb, msglen);
  1407. }
  1408. /**
  1409. * nlmsg_notify - send a notification netlink message
  1410. * @sk: netlink socket to use
  1411. * @skb: notification message
  1412. * @pid: destination netlink pid for reports or 0
  1413. * @group: destination multicast group or 0
  1414. * @report: 1 to report back, 0 to disable
  1415. * @flags: allocation flags
  1416. */
  1417. int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 pid,
  1418. unsigned int group, int report, gfp_t flags)
  1419. {
  1420. int err = 0;
  1421. if (group) {
  1422. int exclude_pid = 0;
  1423. if (report) {
  1424. atomic_inc(&skb->users);
  1425. exclude_pid = pid;
  1426. }
  1427. /* errors reported via destination sk->sk_err */
  1428. nlmsg_multicast(sk, skb, exclude_pid, group, flags);
  1429. }
  1430. if (report)
  1431. err = nlmsg_unicast(sk, skb, pid);
  1432. return err;
  1433. }
  1434. #ifdef CONFIG_PROC_FS
  1435. struct nl_seq_iter {
  1436. struct net *net;
  1437. int link;
  1438. int hash_idx;
  1439. };
  1440. static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
  1441. {
  1442. struct nl_seq_iter *iter = seq->private;
  1443. int i, j;
  1444. struct sock *s;
  1445. struct hlist_node *node;
  1446. loff_t off = 0;
  1447. for (i=0; i<MAX_LINKS; i++) {
  1448. struct nl_pid_hash *hash = &nl_table[i].hash;
  1449. for (j = 0; j <= hash->mask; j++) {
  1450. sk_for_each(s, node, &hash->table[j]) {
  1451. if (iter->net != s->sk_net)
  1452. continue;
  1453. if (off == pos) {
  1454. iter->link = i;
  1455. iter->hash_idx = j;
  1456. return s;
  1457. }
  1458. ++off;
  1459. }
  1460. }
  1461. }
  1462. return NULL;
  1463. }
  1464. static void *netlink_seq_start(struct seq_file *seq, loff_t *pos)
  1465. {
  1466. read_lock(&nl_table_lock);
  1467. return *pos ? netlink_seq_socket_idx(seq, *pos - 1) : SEQ_START_TOKEN;
  1468. }
  1469. static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1470. {
  1471. struct sock *s;
  1472. struct nl_seq_iter *iter;
  1473. int i, j;
  1474. ++*pos;
  1475. if (v == SEQ_START_TOKEN)
  1476. return netlink_seq_socket_idx(seq, 0);
  1477. iter = seq->private;
  1478. s = v;
  1479. do {
  1480. s = sk_next(s);
  1481. } while (s && (iter->net != s->sk_net));
  1482. if (s)
  1483. return s;
  1484. i = iter->link;
  1485. j = iter->hash_idx + 1;
  1486. do {
  1487. struct nl_pid_hash *hash = &nl_table[i].hash;
  1488. for (; j <= hash->mask; j++) {
  1489. s = sk_head(&hash->table[j]);
  1490. while (s && (iter->net != s->sk_net))
  1491. s = sk_next(s);
  1492. if (s) {
  1493. iter->link = i;
  1494. iter->hash_idx = j;
  1495. return s;
  1496. }
  1497. }
  1498. j = 0;
  1499. } while (++i < MAX_LINKS);
  1500. return NULL;
  1501. }
  1502. static void netlink_seq_stop(struct seq_file *seq, void *v)
  1503. {
  1504. read_unlock(&nl_table_lock);
  1505. }
  1506. static int netlink_seq_show(struct seq_file *seq, void *v)
  1507. {
  1508. if (v == SEQ_START_TOKEN)
  1509. seq_puts(seq,
  1510. "sk Eth Pid Groups "
  1511. "Rmem Wmem Dump Locks\n");
  1512. else {
  1513. struct sock *s = v;
  1514. struct netlink_sock *nlk = nlk_sk(s);
  1515. seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %d\n",
  1516. s,
  1517. s->sk_protocol,
  1518. nlk->pid,
  1519. nlk->groups ? (u32)nlk->groups[0] : 0,
  1520. atomic_read(&s->sk_rmem_alloc),
  1521. atomic_read(&s->sk_wmem_alloc),
  1522. nlk->cb,
  1523. atomic_read(&s->sk_refcnt)
  1524. );
  1525. }
  1526. return 0;
  1527. }
  1528. static const struct seq_operations netlink_seq_ops = {
  1529. .start = netlink_seq_start,
  1530. .next = netlink_seq_next,
  1531. .stop = netlink_seq_stop,
  1532. .show = netlink_seq_show,
  1533. };
  1534. static int netlink_seq_open(struct inode *inode, struct file *file)
  1535. {
  1536. struct seq_file *seq;
  1537. struct nl_seq_iter *iter;
  1538. int err;
  1539. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  1540. if (!iter)
  1541. return -ENOMEM;
  1542. err = seq_open(file, &netlink_seq_ops);
  1543. if (err) {
  1544. kfree(iter);
  1545. return err;
  1546. }
  1547. seq = file->private_data;
  1548. seq->private = iter;
  1549. iter->net = get_proc_net(inode);
  1550. if (!iter->net) {
  1551. seq_release_private(inode, file);
  1552. return -ENXIO;
  1553. }
  1554. return 0;
  1555. }
  1556. static int netlink_seq_release(struct inode *inode, struct file *file)
  1557. {
  1558. struct seq_file *seq = file->private_data;
  1559. struct nl_seq_iter *iter = seq->private;
  1560. put_net(iter->net);
  1561. return seq_release_private(inode, file);
  1562. }
  1563. static const struct file_operations netlink_seq_fops = {
  1564. .owner = THIS_MODULE,
  1565. .open = netlink_seq_open,
  1566. .read = seq_read,
  1567. .llseek = seq_lseek,
  1568. .release = netlink_seq_release,
  1569. };
  1570. #endif
  1571. int netlink_register_notifier(struct notifier_block *nb)
  1572. {
  1573. return atomic_notifier_chain_register(&netlink_chain, nb);
  1574. }
  1575. int netlink_unregister_notifier(struct notifier_block *nb)
  1576. {
  1577. return atomic_notifier_chain_unregister(&netlink_chain, nb);
  1578. }
  1579. static const struct proto_ops netlink_ops = {
  1580. .family = PF_NETLINK,
  1581. .owner = THIS_MODULE,
  1582. .release = netlink_release,
  1583. .bind = netlink_bind,
  1584. .connect = netlink_connect,
  1585. .socketpair = sock_no_socketpair,
  1586. .accept = sock_no_accept,
  1587. .getname = netlink_getname,
  1588. .poll = datagram_poll,
  1589. .ioctl = sock_no_ioctl,
  1590. .listen = sock_no_listen,
  1591. .shutdown = sock_no_shutdown,
  1592. .setsockopt = netlink_setsockopt,
  1593. .getsockopt = netlink_getsockopt,
  1594. .sendmsg = netlink_sendmsg,
  1595. .recvmsg = netlink_recvmsg,
  1596. .mmap = sock_no_mmap,
  1597. .sendpage = sock_no_sendpage,
  1598. };
  1599. static struct net_proto_family netlink_family_ops = {
  1600. .family = PF_NETLINK,
  1601. .create = netlink_create,
  1602. .owner = THIS_MODULE, /* for consistency 8) */
  1603. };
  1604. static int netlink_net_init(struct net *net)
  1605. {
  1606. #ifdef CONFIG_PROC_FS
  1607. if (!proc_net_fops_create(net, "netlink", 0, &netlink_seq_fops))
  1608. return -ENOMEM;
  1609. #endif
  1610. return 0;
  1611. }
  1612. static void netlink_net_exit(struct net *net)
  1613. {
  1614. #ifdef CONFIG_PROC_FS
  1615. proc_net_remove(net, "netlink");
  1616. #endif
  1617. }
  1618. static struct pernet_operations netlink_net_ops = {
  1619. .init = netlink_net_init,
  1620. .exit = netlink_net_exit,
  1621. };
  1622. static int __init netlink_proto_init(void)
  1623. {
  1624. struct sk_buff *dummy_skb;
  1625. int i;
  1626. unsigned long max;
  1627. unsigned int order;
  1628. int err = proto_register(&netlink_proto, 0);
  1629. if (err != 0)
  1630. goto out;
  1631. BUILD_BUG_ON(sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb));
  1632. nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL);
  1633. if (!nl_table)
  1634. goto panic;
  1635. if (num_physpages >= (128 * 1024))
  1636. max = num_physpages >> (21 - PAGE_SHIFT);
  1637. else
  1638. max = num_physpages >> (23 - PAGE_SHIFT);
  1639. order = get_bitmask_order(max) - 1 + PAGE_SHIFT;
  1640. max = (1UL << order) / sizeof(struct hlist_head);
  1641. order = get_bitmask_order(max > UINT_MAX ? UINT_MAX : max) - 1;
  1642. for (i = 0; i < MAX_LINKS; i++) {
  1643. struct nl_pid_hash *hash = &nl_table[i].hash;
  1644. hash->table = nl_pid_hash_alloc(1 * sizeof(*hash->table));
  1645. if (!hash->table) {
  1646. while (i-- > 0)
  1647. nl_pid_hash_free(nl_table[i].hash.table,
  1648. 1 * sizeof(*hash->table));
  1649. kfree(nl_table);
  1650. goto panic;
  1651. }
  1652. memset(hash->table, 0, 1 * sizeof(*hash->table));
  1653. hash->max_shift = order;
  1654. hash->shift = 0;
  1655. hash->mask = 0;
  1656. hash->rehash_time = jiffies;
  1657. }
  1658. sock_register(&netlink_family_ops);
  1659. register_pernet_subsys(&netlink_net_ops);
  1660. /* The netlink device handler may be needed early. */
  1661. rtnetlink_init();
  1662. out:
  1663. return err;
  1664. panic:
  1665. panic("netlink_init: Cannot allocate nl_table\n");
  1666. }
  1667. core_initcall(netlink_proto_init);
  1668. EXPORT_SYMBOL(netlink_ack);
  1669. EXPORT_SYMBOL(netlink_run_queue);
  1670. EXPORT_SYMBOL(netlink_broadcast);
  1671. EXPORT_SYMBOL(netlink_dump_start);
  1672. EXPORT_SYMBOL(netlink_kernel_create);
  1673. EXPORT_SYMBOL(netlink_register_notifier);
  1674. EXPORT_SYMBOL(netlink_set_nonroot);
  1675. EXPORT_SYMBOL(netlink_unicast);
  1676. EXPORT_SYMBOL(netlink_unregister_notifier);
  1677. EXPORT_SYMBOL(nlmsg_notify);