net_iptables.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /**
  2. * @file net_iptables.c
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * iptables and ebtables module.
  32. *
  33. * Note that all iptables/ebtables commands (in general) must be issued synchronously, or
  34. * the kernel may randomly report errors if there is another iptables/ebtables command in
  35. * progress. To solve this, the NCD process contains a single "iptables lock". All
  36. * iptables/ebtables commands exposed here go through that lock.
  37. * In case you wish to call iptables/ebtables directly, the lock is exposed via
  38. * net.iptables.lock().
  39. *
  40. * Synopsis:
  41. * net.iptables.append(string table, string chain, string arg1 ...)
  42. * Description:
  43. * init: iptables -t table -A chain arg1 ...
  44. * deinit: iptables -t table -D chain arg1 ...
  45. *
  46. * Synopsis:
  47. * net.iptables.policy(string table, string chain, string target, string revert_target)
  48. * Description:
  49. * init: iptables -t table -P chain target
  50. * deinit: iptables -t table -P chain revert_target
  51. *
  52. * Synopsis:
  53. * net.iptables.newchain(string table, string chain)
  54. * net.iptables.newchain(string chain) // DEPRECATED, defaults to table="filter"
  55. * Description:
  56. * init: iptables -t table -N chain
  57. * deinit: iptables -t table -X chain
  58. *
  59. * Synopsis:
  60. * net.ebtables.append(string table, string chain, string arg1 ...)
  61. * Description:
  62. * init: ebtables -t table -A chain arg1 ...
  63. * deinit: ebtables -t table -D chain arg1 ...
  64. *
  65. * Synopsis:
  66. * net.ebtables.policy(string table, string chain, string target, string revert_target)
  67. * Description:
  68. * init: ebtables -t table -P chain target
  69. * deinit: ebtables -t table -P chain revert_target
  70. *
  71. * Synopsis:
  72. * net.ebtables.newchain(string table, string chain)
  73. * Description:
  74. * init: ebtables -t table -N chain
  75. * deinit: ebtables -t table -X chain
  76. *
  77. * Synopsis:
  78. * net.iptables.lock()
  79. * Description:
  80. * Use at the beginning of a block of custom iptables/ebtables commands to make sure
  81. * they do not interfere with other iptables/ebtables commands.
  82. * WARNING: improper usage of the lock can lead to deadlock. In particular:
  83. * - Do not call any of the iptables/ebtables wrappers above from a lock section;
  84. * those will attempt to aquire the lock themselves.
  85. * - Do not enter another lock section from a lock section.
  86. * - Do not perform any potentially long wait from a lock section.
  87. *
  88. * Synopsis:
  89. * net.iptables.lock::unlock()
  90. * Description:
  91. * Use at the end of a block of custom iptables/ebtables commands to make sure
  92. * they do not interfere with other iptables/ebtables commands.
  93. */
  94. #include <stdlib.h>
  95. #include <string.h>
  96. #include <unistd.h>
  97. #include <misc/debug.h>
  98. #include <misc/find_program.h>
  99. #include <ncd/extra/BEventLock.h>
  100. #include <ncd/modules/command_template.h>
  101. #include <generated/blog_channel_ncd_net_iptables.h>
  102. #define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
  103. static void template_free_func (void *vo, int is_error);
  104. static BEventLock iptables_lock;
  105. struct instance {
  106. NCDModuleInst *i;
  107. command_template_instance cti;
  108. };
  109. struct unlock_instance;
  110. #define LOCK_STATE_LOCKING 1
  111. #define LOCK_STATE_LOCKED 2
  112. #define LOCK_STATE_UNLOCKED 3
  113. #define LOCK_STATE_RELOCKING 4
  114. struct lock_instance {
  115. NCDModuleInst *i;
  116. BEventLockJob lock_job;
  117. struct unlock_instance *unlock;
  118. int state;
  119. };
  120. struct unlock_instance {
  121. NCDModuleInst *i;
  122. struct lock_instance *lock;
  123. };
  124. static void unlock_free (struct unlock_instance *o);
  125. static int build_append_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  126. {
  127. // read arguments
  128. NCDValRef table_arg;
  129. NCDValRef chain_arg;
  130. if (!NCDVal_ListReadHead(args, 2, &table_arg, &chain_arg)) {
  131. ModuleLog(i, BLOG_ERROR, "wrong arity");
  132. goto fail0;
  133. }
  134. if (!NCDVal_IsStringNoNulls(table_arg) || !NCDVal_IsStringNoNulls(chain_arg)) {
  135. ModuleLog(i, BLOG_ERROR, "wrong type");
  136. goto fail0;
  137. }
  138. const char *table = NCDVal_StringData(table_arg);
  139. size_t table_len = NCDVal_StringLength(table_arg);
  140. const char *chain = NCDVal_StringData(chain_arg);
  141. size_t chain_len = NCDVal_StringLength(chain_arg);
  142. // find program
  143. if (!(*exec = badvpn_find_program(prog))) {
  144. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  145. goto fail0;
  146. }
  147. // start cmdline
  148. if (!CmdLine_Init(cl)) {
  149. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  150. goto fail1;
  151. }
  152. // add header
  153. if (!CmdLine_Append(cl, *exec) || !CmdLine_Append(cl, "-t") || !CmdLine_AppendNoNull(cl, table, table_len) || !CmdLine_Append(cl, (remove ? "-D" : "-A")) || !CmdLine_AppendNoNull(cl, chain, chain_len)) {
  154. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  155. goto fail2;
  156. }
  157. // add additional arguments
  158. size_t count = NCDVal_ListCount(args);
  159. for (size_t j = 2; j < count; j++) {
  160. NCDValRef arg = NCDVal_ListGet(args, j);
  161. if (!NCDVal_IsStringNoNulls(arg)) {
  162. ModuleLog(i, BLOG_ERROR, "wrong type");
  163. goto fail2;
  164. }
  165. if (!CmdLine_AppendNoNull(cl, NCDVal_StringData(arg), NCDVal_StringLength(arg))) {
  166. ModuleLog(i, BLOG_ERROR, "CmdLine_AppendNoNull failed");
  167. goto fail2;
  168. }
  169. }
  170. // finish
  171. if (!CmdLine_Finish(cl)) {
  172. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  173. goto fail2;
  174. }
  175. return 1;
  176. fail2:
  177. CmdLine_Free(cl);
  178. fail1:
  179. free(*exec);
  180. fail0:
  181. return 0;
  182. }
  183. static int build_policy_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  184. {
  185. // read arguments
  186. NCDValRef table_arg;
  187. NCDValRef chain_arg;
  188. NCDValRef target_arg;
  189. NCDValRef revert_target_arg;
  190. if (!NCDVal_ListRead(args, 4, &table_arg, &chain_arg, &target_arg, &revert_target_arg)) {
  191. ModuleLog(i, BLOG_ERROR, "wrong arity");
  192. goto fail0;
  193. }
  194. if (!NCDVal_IsStringNoNulls(table_arg) || !NCDVal_IsStringNoNulls(chain_arg) ||
  195. !NCDVal_IsStringNoNulls(target_arg) || !NCDVal_IsStringNoNulls(revert_target_arg)
  196. ) {
  197. ModuleLog(i, BLOG_ERROR, "wrong type");
  198. goto fail0;
  199. }
  200. const char *table = NCDVal_StringData(table_arg);
  201. size_t table_len = NCDVal_StringLength(table_arg);
  202. const char *chain = NCDVal_StringData(chain_arg);
  203. size_t chain_len = NCDVal_StringLength(chain_arg);
  204. const char *target = NCDVal_StringData(target_arg);
  205. size_t target_len = NCDVal_StringLength(target_arg);
  206. const char *revert_target = NCDVal_StringData(revert_target_arg);
  207. size_t revert_target_len = NCDVal_StringLength(revert_target_arg);
  208. // find program
  209. if (!(*exec = badvpn_find_program(prog))) {
  210. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  211. goto fail0;
  212. }
  213. // start cmdline
  214. if (!CmdLine_Init(cl)) {
  215. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  216. goto fail1;
  217. }
  218. // add arguments
  219. if (!CmdLine_Append(cl, *exec) || !CmdLine_Append(cl, "-t") || !CmdLine_AppendNoNull(cl, table, table_len) ||
  220. !CmdLine_Append(cl, "-P") || !CmdLine_AppendNoNull(cl, chain, chain_len) ||
  221. !CmdLine_AppendNoNull(cl, (remove ? revert_target : target), (remove ? revert_target_len : target_len))
  222. ) {
  223. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  224. goto fail2;
  225. }
  226. // finish
  227. if (!CmdLine_Finish(cl)) {
  228. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  229. goto fail2;
  230. }
  231. return 1;
  232. fail2:
  233. CmdLine_Free(cl);
  234. fail1:
  235. free(*exec);
  236. fail0:
  237. return 0;
  238. }
  239. static int build_newchain_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  240. {
  241. // read arguments
  242. NCDValRef table_arg = NCDVal_NewInvalid();
  243. NCDValRef chain_arg;
  244. if (!NCDVal_ListRead(args, 1, &chain_arg) && !NCDVal_ListRead(args, 2, &table_arg, &chain_arg)) {
  245. ModuleLog(i, BLOG_ERROR, "wrong arity");
  246. goto fail0;
  247. }
  248. if ((!NCDVal_IsInvalid(table_arg) && !NCDVal_IsStringNoNulls(table_arg)) || !NCDVal_IsStringNoNulls(chain_arg)) {
  249. ModuleLog(i, BLOG_ERROR, "wrong type");
  250. goto fail0;
  251. }
  252. const char *table = (NCDVal_IsInvalid(table_arg) ? "filter" : NCDVal_StringData(table_arg));
  253. size_t table_len = (NCDVal_IsInvalid(table_arg) ? 6 : NCDVal_StringLength(table_arg));
  254. const char *chain = NCDVal_StringData(chain_arg);
  255. size_t chain_len = NCDVal_StringLength(chain_arg);
  256. // find program
  257. if (!(*exec = badvpn_find_program(prog))) {
  258. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  259. goto fail0;
  260. }
  261. // start cmdline
  262. if (!CmdLine_Init(cl)) {
  263. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  264. goto fail1;
  265. }
  266. // add arguments
  267. if (!CmdLine_AppendMulti(cl, 2, *exec, "-t") ||
  268. !CmdLine_AppendNoNull(cl, table, table_len) ||
  269. !CmdLine_Append(cl, (remove ? "-X" : "-N")) ||
  270. !CmdLine_AppendNoNull(cl, chain, chain_len)
  271. ) {
  272. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  273. goto fail2;
  274. }
  275. // finish
  276. if (!CmdLine_Finish(cl)) {
  277. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  278. goto fail2;
  279. }
  280. return 1;
  281. fail2:
  282. CmdLine_Free(cl);
  283. fail1:
  284. free(*exec);
  285. fail0:
  286. return 0;
  287. }
  288. static int build_iptables_append_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  289. {
  290. return build_append_cmdline(i, args, "iptables", remove, exec, cl);
  291. }
  292. static int build_iptables_policy_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  293. {
  294. return build_policy_cmdline(i, args, "iptables", remove, exec, cl);
  295. }
  296. static int build_iptables_newchain_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  297. {
  298. return build_newchain_cmdline(i, args, "iptables", remove, exec, cl);
  299. }
  300. static int build_ebtables_append_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  301. {
  302. return build_append_cmdline(i, args, "ebtables", remove, exec, cl);
  303. }
  304. static int build_ebtables_policy_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  305. {
  306. return build_policy_cmdline(i, args, "ebtables", remove, exec, cl);
  307. }
  308. static int build_ebtables_newchain_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  309. {
  310. return build_newchain_cmdline(i, args, "ebtables", remove, exec, cl);
  311. }
  312. static void lock_job_handler (struct lock_instance *o)
  313. {
  314. ASSERT(o->state == LOCK_STATE_LOCKING || o->state == LOCK_STATE_RELOCKING)
  315. if (o->state == LOCK_STATE_LOCKING) {
  316. ASSERT(!o->unlock)
  317. // up
  318. NCDModuleInst_Backend_Up(o->i);
  319. // set state locked
  320. o->state = LOCK_STATE_LOCKED;
  321. }
  322. else if (o->state == LOCK_STATE_RELOCKING) {
  323. ASSERT(o->unlock)
  324. ASSERT(o->unlock->lock == o)
  325. // die unlock
  326. unlock_free(o->unlock);
  327. o->unlock = NULL;
  328. // set state locked
  329. o->state = LOCK_STATE_LOCKED;
  330. }
  331. }
  332. static int func_globalinit (struct NCDInterpModuleGroup *group, const struct NCDModuleInst_iparams *params)
  333. {
  334. // init iptables lock
  335. BEventLock_Init(&iptables_lock, BReactor_PendingGroup(params->reactor));
  336. return 1;
  337. }
  338. static void func_globalfree (struct NCDInterpModuleGroup *group)
  339. {
  340. // free iptables lock
  341. BEventLock_Free(&iptables_lock);
  342. }
  343. static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, command_template_build_cmdline build_cmdline)
  344. {
  345. struct instance *o = vo;
  346. o->i = i;
  347. command_template_new(&o->cti, i, params, build_cmdline, template_free_func, o, BLOG_CURRENT_CHANNEL, &iptables_lock);
  348. }
  349. void template_free_func (void *vo, int is_error)
  350. {
  351. struct instance *o = vo;
  352. if (is_error) {
  353. NCDModuleInst_Backend_DeadError(o->i);
  354. } else {
  355. NCDModuleInst_Backend_Dead(o->i);
  356. }
  357. }
  358. static void append_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  359. {
  360. func_new(vo, i, params, build_iptables_append_cmdline);
  361. }
  362. static void policy_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  363. {
  364. func_new(vo, i, params, build_iptables_policy_cmdline);
  365. }
  366. static void newchain_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  367. {
  368. func_new(vo, i, params, build_iptables_newchain_cmdline);
  369. }
  370. static void append_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  371. {
  372. func_new(vo, i, params, build_ebtables_append_cmdline);
  373. }
  374. static void policy_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  375. {
  376. func_new(vo, i, params, build_ebtables_policy_cmdline);
  377. }
  378. static void newchain_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  379. {
  380. func_new(vo, i, params, build_ebtables_newchain_cmdline);
  381. }
  382. static void func_die (void *vo)
  383. {
  384. struct instance *o = vo;
  385. command_template_die(&o->cti);
  386. }
  387. static void lock_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  388. {
  389. struct lock_instance *o = vo;
  390. o->i = i;
  391. // init lock job
  392. BEventLockJob_Init(&o->lock_job, &iptables_lock, (BEventLock_handler)lock_job_handler, o);
  393. BEventLockJob_Wait(&o->lock_job);
  394. // set no unlock
  395. o->unlock = NULL;
  396. // set state locking
  397. o->state = LOCK_STATE_LOCKING;
  398. }
  399. static void lock_func_die (void *vo)
  400. {
  401. struct lock_instance *o = vo;
  402. if (o->state == LOCK_STATE_UNLOCKED) {
  403. ASSERT(o->unlock)
  404. ASSERT(o->unlock->lock == o)
  405. o->unlock->lock = NULL;
  406. }
  407. else if (o->state == LOCK_STATE_RELOCKING) {
  408. ASSERT(o->unlock)
  409. ASSERT(o->unlock->lock == o)
  410. unlock_free(o->unlock);
  411. }
  412. else {
  413. ASSERT(!o->unlock)
  414. }
  415. // free lock job
  416. BEventLockJob_Free(&o->lock_job);
  417. // dead
  418. NCDModuleInst_Backend_Dead(o->i);
  419. }
  420. static void unlock_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  421. {
  422. struct unlock_instance *o = vo;
  423. o->i = i;
  424. // get lock lock
  425. struct lock_instance *lock = NCDModuleInst_Backend_GetUser((NCDModuleInst *)params->method_user);
  426. // make sure lock doesn't already have an unlock
  427. if (lock->unlock) {
  428. BLog(BLOG_ERROR, "lock already has an unlock");
  429. goto fail0;
  430. }
  431. // make sure lock is locked
  432. if (lock->state != LOCK_STATE_LOCKED) {
  433. BLog(BLOG_ERROR, "lock is not locked");
  434. goto fail0;
  435. }
  436. // set lock
  437. o->lock = lock;
  438. // set unlock in lock
  439. lock->unlock = o;
  440. // up
  441. NCDModuleInst_Backend_Up(o->i);
  442. // release lock
  443. BEventLockJob_Release(&lock->lock_job);
  444. // set lock state unlocked
  445. lock->state = LOCK_STATE_UNLOCKED;
  446. return;
  447. fail0:
  448. NCDModuleInst_Backend_DeadError(i);
  449. }
  450. static void unlock_func_die (void *vo)
  451. {
  452. struct unlock_instance *o = vo;
  453. // if lock is gone, die right away
  454. if (!o->lock) {
  455. unlock_free(o);
  456. return;
  457. }
  458. ASSERT(o->lock->unlock == o)
  459. ASSERT(o->lock->state == LOCK_STATE_UNLOCKED)
  460. // wait lock
  461. BEventLockJob_Wait(&o->lock->lock_job);
  462. // set lock state relocking
  463. o->lock->state = LOCK_STATE_RELOCKING;
  464. }
  465. static void unlock_free (struct unlock_instance *o)
  466. {
  467. NCDModuleInst_Backend_Dead(o->i);
  468. }
  469. static struct NCDModule modules[] = {
  470. {
  471. .type = "net.iptables.append",
  472. .func_new2 = append_iptables_func_new,
  473. .func_die = func_die,
  474. .alloc_size = sizeof(struct instance)
  475. }, {
  476. .type = "net.iptables.policy",
  477. .func_new2 = policy_iptables_func_new,
  478. .func_die = func_die,
  479. .alloc_size = sizeof(struct instance)
  480. }, {
  481. .type = "net.iptables.newchain",
  482. .func_new2 = newchain_iptables_func_new,
  483. .func_die = func_die,
  484. .alloc_size = sizeof(struct instance)
  485. }, {
  486. .type = "net.ebtables.append",
  487. .func_new2 = append_ebtables_func_new,
  488. .func_die = func_die,
  489. .alloc_size = sizeof(struct instance)
  490. }, {
  491. .type = "net.ebtables.policy",
  492. .func_new2 = policy_ebtables_func_new,
  493. .func_die = func_die,
  494. .alloc_size = sizeof(struct instance)
  495. }, {
  496. .type = "net.ebtables.newchain",
  497. .func_new2 = newchain_ebtables_func_new,
  498. .func_die = func_die,
  499. .alloc_size = sizeof(struct instance)
  500. }, {
  501. .type = "net.iptables.lock",
  502. .func_new2 = lock_func_new,
  503. .func_die = lock_func_die,
  504. .alloc_size = sizeof(struct lock_instance)
  505. }, {
  506. .type = "net.iptables.lock::unlock",
  507. .func_new2 = unlock_func_new,
  508. .func_die = unlock_func_die,
  509. .alloc_size = sizeof(struct unlock_instance)
  510. }, {
  511. .type = NULL
  512. }
  513. };
  514. const struct NCDModuleGroup ncdmodule_net_iptables = {
  515. .modules = modules,
  516. .func_globalinit = func_globalinit,
  517. .func_globalfree = func_globalfree
  518. };