net_iptables.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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 <misc/balloc.h>
  100. #include <ncd/extra/BEventLock.h>
  101. #include <ncd/modules/command_template.h>
  102. #include <generated/blog_channel_ncd_net_iptables.h>
  103. #define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
  104. #define ModuleGlobal(i) ((i)->m->group->group_state)
  105. static void template_free_func (void *vo, int is_error);
  106. struct global {
  107. BEventLock iptables_lock;
  108. };
  109. struct instance {
  110. NCDModuleInst *i;
  111. command_template_instance cti;
  112. };
  113. struct unlock_instance;
  114. #define LOCK_STATE_LOCKING 1
  115. #define LOCK_STATE_LOCKED 2
  116. #define LOCK_STATE_UNLOCKED 3
  117. #define LOCK_STATE_RELOCKING 4
  118. struct lock_instance {
  119. NCDModuleInst *i;
  120. BEventLockJob lock_job;
  121. struct unlock_instance *unlock;
  122. int state;
  123. };
  124. struct unlock_instance {
  125. NCDModuleInst *i;
  126. struct lock_instance *lock;
  127. };
  128. static void unlock_free (struct unlock_instance *o);
  129. static int build_append_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  130. {
  131. // read arguments
  132. NCDValRef table_arg;
  133. NCDValRef chain_arg;
  134. if (!NCDVal_ListReadHead(args, 2, &table_arg, &chain_arg)) {
  135. ModuleLog(i, BLOG_ERROR, "wrong arity");
  136. goto fail0;
  137. }
  138. if (!NCDVal_IsStringNoNulls(table_arg) || !NCDVal_IsStringNoNulls(chain_arg)) {
  139. ModuleLog(i, BLOG_ERROR, "wrong type");
  140. goto fail0;
  141. }
  142. const char *table = NCDVal_StringData(table_arg);
  143. size_t table_len = NCDVal_StringLength(table_arg);
  144. const char *chain = NCDVal_StringData(chain_arg);
  145. size_t chain_len = NCDVal_StringLength(chain_arg);
  146. // find program
  147. if (!(*exec = badvpn_find_program(prog))) {
  148. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  149. goto fail0;
  150. }
  151. // start cmdline
  152. if (!CmdLine_Init(cl)) {
  153. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  154. goto fail1;
  155. }
  156. // add header
  157. 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)) {
  158. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  159. goto fail2;
  160. }
  161. // add additional arguments
  162. size_t count = NCDVal_ListCount(args);
  163. for (size_t j = 2; j < count; j++) {
  164. NCDValRef arg = NCDVal_ListGet(args, j);
  165. if (!NCDVal_IsStringNoNulls(arg)) {
  166. ModuleLog(i, BLOG_ERROR, "wrong type");
  167. goto fail2;
  168. }
  169. if (!CmdLine_AppendNoNull(cl, NCDVal_StringData(arg), NCDVal_StringLength(arg))) {
  170. ModuleLog(i, BLOG_ERROR, "CmdLine_AppendNoNull failed");
  171. goto fail2;
  172. }
  173. }
  174. // finish
  175. if (!CmdLine_Finish(cl)) {
  176. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  177. goto fail2;
  178. }
  179. return 1;
  180. fail2:
  181. CmdLine_Free(cl);
  182. fail1:
  183. free(*exec);
  184. fail0:
  185. return 0;
  186. }
  187. static int build_policy_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  188. {
  189. // read arguments
  190. NCDValRef table_arg;
  191. NCDValRef chain_arg;
  192. NCDValRef target_arg;
  193. NCDValRef revert_target_arg;
  194. if (!NCDVal_ListRead(args, 4, &table_arg, &chain_arg, &target_arg, &revert_target_arg)) {
  195. ModuleLog(i, BLOG_ERROR, "wrong arity");
  196. goto fail0;
  197. }
  198. if (!NCDVal_IsStringNoNulls(table_arg) || !NCDVal_IsStringNoNulls(chain_arg) ||
  199. !NCDVal_IsStringNoNulls(target_arg) || !NCDVal_IsStringNoNulls(revert_target_arg)
  200. ) {
  201. ModuleLog(i, BLOG_ERROR, "wrong type");
  202. goto fail0;
  203. }
  204. const char *table = NCDVal_StringData(table_arg);
  205. size_t table_len = NCDVal_StringLength(table_arg);
  206. const char *chain = NCDVal_StringData(chain_arg);
  207. size_t chain_len = NCDVal_StringLength(chain_arg);
  208. const char *target = NCDVal_StringData(target_arg);
  209. size_t target_len = NCDVal_StringLength(target_arg);
  210. const char *revert_target = NCDVal_StringData(revert_target_arg);
  211. size_t revert_target_len = NCDVal_StringLength(revert_target_arg);
  212. // find program
  213. if (!(*exec = badvpn_find_program(prog))) {
  214. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  215. goto fail0;
  216. }
  217. // start cmdline
  218. if (!CmdLine_Init(cl)) {
  219. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  220. goto fail1;
  221. }
  222. // add arguments
  223. if (!CmdLine_Append(cl, *exec) || !CmdLine_Append(cl, "-t") || !CmdLine_AppendNoNull(cl, table, table_len) ||
  224. !CmdLine_Append(cl, "-P") || !CmdLine_AppendNoNull(cl, chain, chain_len) ||
  225. !CmdLine_AppendNoNull(cl, (remove ? revert_target : target), (remove ? revert_target_len : target_len))
  226. ) {
  227. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  228. goto fail2;
  229. }
  230. // finish
  231. if (!CmdLine_Finish(cl)) {
  232. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  233. goto fail2;
  234. }
  235. return 1;
  236. fail2:
  237. CmdLine_Free(cl);
  238. fail1:
  239. free(*exec);
  240. fail0:
  241. return 0;
  242. }
  243. static int build_newchain_cmdline (NCDModuleInst *i, NCDValRef args, const char *prog, int remove, char **exec, CmdLine *cl)
  244. {
  245. // read arguments
  246. NCDValRef table_arg = NCDVal_NewInvalid();
  247. NCDValRef chain_arg;
  248. if (!NCDVal_ListRead(args, 1, &chain_arg) && !NCDVal_ListRead(args, 2, &table_arg, &chain_arg)) {
  249. ModuleLog(i, BLOG_ERROR, "wrong arity");
  250. goto fail0;
  251. }
  252. if ((!NCDVal_IsInvalid(table_arg) && !NCDVal_IsStringNoNulls(table_arg)) || !NCDVal_IsStringNoNulls(chain_arg)) {
  253. ModuleLog(i, BLOG_ERROR, "wrong type");
  254. goto fail0;
  255. }
  256. const char *table = (NCDVal_IsInvalid(table_arg) ? "filter" : NCDVal_StringData(table_arg));
  257. size_t table_len = (NCDVal_IsInvalid(table_arg) ? 6 : NCDVal_StringLength(table_arg));
  258. const char *chain = NCDVal_StringData(chain_arg);
  259. size_t chain_len = NCDVal_StringLength(chain_arg);
  260. // find program
  261. if (!(*exec = badvpn_find_program(prog))) {
  262. ModuleLog(i, BLOG_ERROR, "failed to find program: %s", prog);
  263. goto fail0;
  264. }
  265. // start cmdline
  266. if (!CmdLine_Init(cl)) {
  267. ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
  268. goto fail1;
  269. }
  270. // add arguments
  271. if (!CmdLine_AppendMulti(cl, 2, *exec, "-t") ||
  272. !CmdLine_AppendNoNull(cl, table, table_len) ||
  273. !CmdLine_Append(cl, (remove ? "-X" : "-N")) ||
  274. !CmdLine_AppendNoNull(cl, chain, chain_len)
  275. ) {
  276. ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
  277. goto fail2;
  278. }
  279. // finish
  280. if (!CmdLine_Finish(cl)) {
  281. ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
  282. goto fail2;
  283. }
  284. return 1;
  285. fail2:
  286. CmdLine_Free(cl);
  287. fail1:
  288. free(*exec);
  289. fail0:
  290. return 0;
  291. }
  292. static int build_iptables_append_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  293. {
  294. return build_append_cmdline(i, args, "iptables", remove, exec, cl);
  295. }
  296. static int build_iptables_policy_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  297. {
  298. return build_policy_cmdline(i, args, "iptables", remove, exec, cl);
  299. }
  300. static int build_iptables_newchain_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  301. {
  302. return build_newchain_cmdline(i, args, "iptables", remove, exec, cl);
  303. }
  304. static int build_ebtables_append_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  305. {
  306. return build_append_cmdline(i, args, "ebtables", remove, exec, cl);
  307. }
  308. static int build_ebtables_policy_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  309. {
  310. return build_policy_cmdline(i, args, "ebtables", remove, exec, cl);
  311. }
  312. static int build_ebtables_newchain_cmdline (NCDModuleInst *i, NCDValRef args, int remove, char **exec, CmdLine *cl)
  313. {
  314. return build_newchain_cmdline(i, args, "ebtables", remove, exec, cl);
  315. }
  316. static void lock_job_handler (struct lock_instance *o)
  317. {
  318. ASSERT(o->state == LOCK_STATE_LOCKING || o->state == LOCK_STATE_RELOCKING)
  319. if (o->state == LOCK_STATE_LOCKING) {
  320. ASSERT(!o->unlock)
  321. // up
  322. NCDModuleInst_Backend_Up(o->i);
  323. // set state locked
  324. o->state = LOCK_STATE_LOCKED;
  325. }
  326. else if (o->state == LOCK_STATE_RELOCKING) {
  327. ASSERT(o->unlock)
  328. ASSERT(o->unlock->lock == o)
  329. // die unlock
  330. unlock_free(o->unlock);
  331. o->unlock = NULL;
  332. // set state locked
  333. o->state = LOCK_STATE_LOCKED;
  334. }
  335. }
  336. static int func_globalinit (struct NCDInterpModuleGroup *group, const struct NCDModuleInst_iparams *params)
  337. {
  338. // allocate global state structure
  339. struct global *g = BAlloc(sizeof(*g));
  340. if (!g) {
  341. BLog(BLOG_ERROR, "BAlloc failed");
  342. return 0;
  343. }
  344. // set group state pointer
  345. group->group_state = g;
  346. // init iptables lock
  347. BEventLock_Init(&g->iptables_lock, BReactor_PendingGroup(params->reactor));
  348. return 1;
  349. }
  350. static void func_globalfree (struct NCDInterpModuleGroup *group)
  351. {
  352. struct global *g = group->group_state;
  353. // free iptables lock
  354. BEventLock_Free(&g->iptables_lock);
  355. // free global state structure
  356. BFree(g);
  357. }
  358. static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, command_template_build_cmdline build_cmdline)
  359. {
  360. struct global *g = ModuleGlobal(i);
  361. struct instance *o = vo;
  362. o->i = i;
  363. command_template_new(&o->cti, i, params, build_cmdline, template_free_func, o, BLOG_CURRENT_CHANNEL, &g->iptables_lock);
  364. }
  365. void template_free_func (void *vo, int is_error)
  366. {
  367. struct instance *o = vo;
  368. if (is_error) {
  369. NCDModuleInst_Backend_DeadError(o->i);
  370. } else {
  371. NCDModuleInst_Backend_Dead(o->i);
  372. }
  373. }
  374. static void append_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  375. {
  376. func_new(vo, i, params, build_iptables_append_cmdline);
  377. }
  378. static void policy_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  379. {
  380. func_new(vo, i, params, build_iptables_policy_cmdline);
  381. }
  382. static void newchain_iptables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  383. {
  384. func_new(vo, i, params, build_iptables_newchain_cmdline);
  385. }
  386. static void append_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  387. {
  388. func_new(vo, i, params, build_ebtables_append_cmdline);
  389. }
  390. static void policy_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  391. {
  392. func_new(vo, i, params, build_ebtables_policy_cmdline);
  393. }
  394. static void newchain_ebtables_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  395. {
  396. func_new(vo, i, params, build_ebtables_newchain_cmdline);
  397. }
  398. static void func_die (void *vo)
  399. {
  400. struct instance *o = vo;
  401. command_template_die(&o->cti);
  402. }
  403. static void lock_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  404. {
  405. struct global *g = ModuleGlobal(i);
  406. struct lock_instance *o = vo;
  407. o->i = i;
  408. // init lock job
  409. BEventLockJob_Init(&o->lock_job, &g->iptables_lock, (BEventLock_handler)lock_job_handler, o);
  410. BEventLockJob_Wait(&o->lock_job);
  411. // set no unlock
  412. o->unlock = NULL;
  413. // set state locking
  414. o->state = LOCK_STATE_LOCKING;
  415. }
  416. static void lock_func_die (void *vo)
  417. {
  418. struct lock_instance *o = vo;
  419. if (o->state == LOCK_STATE_UNLOCKED) {
  420. ASSERT(o->unlock)
  421. ASSERT(o->unlock->lock == o)
  422. o->unlock->lock = NULL;
  423. }
  424. else if (o->state == LOCK_STATE_RELOCKING) {
  425. ASSERT(o->unlock)
  426. ASSERT(o->unlock->lock == o)
  427. unlock_free(o->unlock);
  428. }
  429. else {
  430. ASSERT(!o->unlock)
  431. }
  432. // free lock job
  433. BEventLockJob_Free(&o->lock_job);
  434. // dead
  435. NCDModuleInst_Backend_Dead(o->i);
  436. }
  437. static void unlock_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
  438. {
  439. struct unlock_instance *o = vo;
  440. o->i = i;
  441. // get lock lock
  442. struct lock_instance *lock = NCDModuleInst_Backend_GetUser((NCDModuleInst *)params->method_user);
  443. // make sure lock doesn't already have an unlock
  444. if (lock->unlock) {
  445. BLog(BLOG_ERROR, "lock already has an unlock");
  446. goto fail0;
  447. }
  448. // make sure lock is locked
  449. if (lock->state != LOCK_STATE_LOCKED) {
  450. BLog(BLOG_ERROR, "lock is not locked");
  451. goto fail0;
  452. }
  453. // set lock
  454. o->lock = lock;
  455. // set unlock in lock
  456. lock->unlock = o;
  457. // up
  458. NCDModuleInst_Backend_Up(o->i);
  459. // release lock
  460. BEventLockJob_Release(&lock->lock_job);
  461. // set lock state unlocked
  462. lock->state = LOCK_STATE_UNLOCKED;
  463. return;
  464. fail0:
  465. NCDModuleInst_Backend_DeadError(i);
  466. }
  467. static void unlock_func_die (void *vo)
  468. {
  469. struct unlock_instance *o = vo;
  470. // if lock is gone, die right away
  471. if (!o->lock) {
  472. unlock_free(o);
  473. return;
  474. }
  475. ASSERT(o->lock->unlock == o)
  476. ASSERT(o->lock->state == LOCK_STATE_UNLOCKED)
  477. // wait lock
  478. BEventLockJob_Wait(&o->lock->lock_job);
  479. // set lock state relocking
  480. o->lock->state = LOCK_STATE_RELOCKING;
  481. }
  482. static void unlock_free (struct unlock_instance *o)
  483. {
  484. NCDModuleInst_Backend_Dead(o->i);
  485. }
  486. static struct NCDModule modules[] = {
  487. {
  488. .type = "net.iptables.append",
  489. .func_new2 = append_iptables_func_new,
  490. .func_die = func_die,
  491. .alloc_size = sizeof(struct instance)
  492. }, {
  493. .type = "net.iptables.policy",
  494. .func_new2 = policy_iptables_func_new,
  495. .func_die = func_die,
  496. .alloc_size = sizeof(struct instance)
  497. }, {
  498. .type = "net.iptables.newchain",
  499. .func_new2 = newchain_iptables_func_new,
  500. .func_die = func_die,
  501. .alloc_size = sizeof(struct instance)
  502. }, {
  503. .type = "net.ebtables.append",
  504. .func_new2 = append_ebtables_func_new,
  505. .func_die = func_die,
  506. .alloc_size = sizeof(struct instance)
  507. }, {
  508. .type = "net.ebtables.policy",
  509. .func_new2 = policy_ebtables_func_new,
  510. .func_die = func_die,
  511. .alloc_size = sizeof(struct instance)
  512. }, {
  513. .type = "net.ebtables.newchain",
  514. .func_new2 = newchain_ebtables_func_new,
  515. .func_die = func_die,
  516. .alloc_size = sizeof(struct instance)
  517. }, {
  518. .type = "net.iptables.lock",
  519. .func_new2 = lock_func_new,
  520. .func_die = lock_func_die,
  521. .alloc_size = sizeof(struct lock_instance)
  522. }, {
  523. .type = "net.iptables.lock::unlock",
  524. .func_new2 = unlock_func_new,
  525. .func_die = unlock_func_die,
  526. .alloc_size = sizeof(struct unlock_instance)
  527. }, {
  528. .type = NULL
  529. }
  530. };
  531. const struct NCDModuleGroup ncdmodule_net_iptables = {
  532. .modules = modules,
  533. .func_globalinit = func_globalinit,
  534. .func_globalfree = func_globalfree
  535. };