libip6t_DNPT.c revision 7b04e3ef3a6ffccb23de83ef3b2d8f5aeaaa09e5
1#include <stdio.h> 2#include <xtables.h> 3#include <linux/netfilter_ipv6/ip6_tables.h> 4#include <linux/netfilter_ipv6/ip6t_NPT.h> 5 6enum { 7 O_SRC_PFX = 1 << 0, 8 O_DST_PFX = 1 << 1, 9}; 10 11static const struct xt_option_entry DNPT_options[] = { 12 { .name = "src-pfx", .id = O_SRC_PFX, .type = XTTYPE_HOSTMASK, 13 .flags = XTOPT_MAND }, 14 { .name = "dst-pfx", .id = O_DST_PFX, .type = XTTYPE_HOSTMASK, 15 .flags = XTOPT_MAND }, 16 { } 17}; 18 19static void DNPT_help(void) 20{ 21 printf("DNPT target options:" 22 "\n" 23 " --src-pfx prefix/length\n" 24 " --dst-pfx prefix/length\n" 25 "\n"); 26} 27 28static void DNPT_parse(struct xt_option_call *cb) 29{ 30 struct ip6t_npt_tginfo *npt = cb->data; 31 32 xtables_option_parse(cb); 33 switch (cb->entry->id) { 34 case O_SRC_PFX: 35 npt->src_pfx = cb->val.haddr; 36 npt->src_pfx_len = cb->val.hlen; 37 break; 38 case O_DST_PFX: 39 npt->dst_pfx = cb->val.haddr; 40 npt->dst_pfx_len = cb->val.hlen; 41 break; 42 } 43} 44 45static void DNPT_print(const void *ip, const struct xt_entry_target *target, 46 int numeric) 47{ 48 const struct ip6t_npt_tginfo *npt = (const void *)target->data; 49 50 printf("src-pfx %s/%u ", xtables_ip6addr_to_numeric(&npt->src_pfx.in6), 51 npt->src_pfx_len); 52 printf("dst-pfx %s/%u ", xtables_ip6addr_to_numeric(&npt->dst_pfx.in6), 53 npt->dst_pfx_len); 54} 55 56static struct xtables_target snpt_tg_reg = { 57 .name = "DNPT", 58 .version = XTABLES_VERSION, 59 .family = NFPROTO_IPV6, 60 .size = XT_ALIGN(sizeof(struct ip6t_npt_tginfo)), 61 .userspacesize = offsetof(struct ip6t_npt_tginfo, adjustment), 62 .help = DNPT_help, 63 .x6_parse = DNPT_parse, 64 .print = DNPT_print, 65 .x6_options = DNPT_options, 66}; 67 68void _init(void) 69{ 70 xtables_register_target(&snpt_tg_reg); 71} 72