12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322 |
- /*
- * libxt_conntrack
- * Shared library add-on to iptables for conntrack matching support.
- *
- * GPL (C) 2001 Marc Boucher (marc@mbsi.ca).
- * Copyright © CC Computer Consultants GmbH, 2007 - 2008
- * Jan Engelhardt <jengelh@computergmbh.de>
- */
- #include <stdbool.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <xtables.h>
- #include <linux/netfilter/xt_conntrack.h>
- #include <linux/netfilter/xt_state.h>
- #include <linux/netfilter/nf_conntrack_common.h>
- #ifndef XT_STATE_UNTRACKED
- #define XT_STATE_UNTRACKED (1 << (IP_CT_NUMBER + 1))
- #endif
- struct ip_conntrack_old_tuple {
- struct {
- __be32 ip;
- union {
- __u16 all;
- } u;
- } src;
- struct {
- __be32 ip;
- union {
- __u16 all;
- } u;
- /* The protocol. */
- __u16 protonum;
- } dst;
- };
- struct xt_conntrack_info {
- unsigned int statemask, statusmask;
- struct ip_conntrack_old_tuple tuple[IP_CT_DIR_MAX];
- struct in_addr sipmsk[IP_CT_DIR_MAX], dipmsk[IP_CT_DIR_MAX];
- unsigned long expires_min, expires_max;
- /* Flags word */
- uint8_t flags;
- /* Inverse flags */
- uint8_t invflags;
- };
- enum {
- O_CTSTATE = 0,
- O_CTPROTO,
- O_CTORIGSRC,
- O_CTORIGDST,
- O_CTREPLSRC,
- O_CTREPLDST,
- O_CTORIGSRCPORT,
- O_CTORIGDSTPORT,
- O_CTREPLSRCPORT,
- O_CTREPLDSTPORT,
- O_CTSTATUS,
- O_CTEXPIRE,
- O_CTDIR,
- };
- static void conntrack_mt_help(void)
- {
- printf(
- "conntrack match options:\n"
- "[!] --ctstate {INVALID|ESTABLISHED|NEW|RELATED|UNTRACKED|SNAT|DNAT}[,...]\n"
- " State(s) to match\n"
- "[!] --ctproto proto Protocol to match; by number or name, e.g. \"tcp\"\n"
- "[!] --ctorigsrc address[/mask]\n"
- "[!] --ctorigdst address[/mask]\n"
- "[!] --ctreplsrc address[/mask]\n"
- "[!] --ctrepldst address[/mask]\n"
- " Original/Reply source/destination address\n"
- "[!] --ctorigsrcport port\n"
- "[!] --ctorigdstport port\n"
- "[!] --ctreplsrcport port\n"
- "[!] --ctrepldstport port\n"
- " TCP/UDP/SCTP orig./reply source/destination port\n"
- "[!] --ctstatus {NONE|EXPECTED|SEEN_REPLY|ASSURED|CONFIRMED}[,...]\n"
- " Status(es) to match\n"
- "[!] --ctexpire time[:time] Match remaining lifetime in seconds against\n"
- " value or range of values (inclusive)\n"
- " --ctdir {ORIGINAL|REPLY} Flow direction of packet\n");
- }
- #define s struct xt_conntrack_info /* for v0 */
- static const struct xt_option_entry conntrack_mt_opts_v0[] = {
- {.name = "ctstate", .id = O_CTSTATE, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctproto", .id = O_CTPROTO, .type = XTTYPE_PROTOCOL,
- .flags = XTOPT_INVERT},
- {.name = "ctorigsrc", .id = O_CTORIGSRC, .type = XTTYPE_HOST,
- .flags = XTOPT_INVERT},
- {.name = "ctorigdst", .id = O_CTORIGDST, .type = XTTYPE_HOST,
- .flags = XTOPT_INVERT},
- {.name = "ctreplsrc", .id = O_CTREPLSRC, .type = XTTYPE_HOST,
- .flags = XTOPT_INVERT},
- {.name = "ctrepldst", .id = O_CTREPLDST, .type = XTTYPE_HOST,
- .flags = XTOPT_INVERT},
- {.name = "ctstatus", .id = O_CTSTATUS, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctexpire", .id = O_CTEXPIRE, .type = XTTYPE_UINT32RC,
- .flags = XTOPT_INVERT},
- XTOPT_TABLEEND,
- };
- #undef s
- #define s struct xt_conntrack_mtinfo2
- /* We exploit the fact that v1-v2 share the same xt_o_e layout */
- static const struct xt_option_entry conntrack2_mt_opts[] = {
- {.name = "ctstate", .id = O_CTSTATE, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctproto", .id = O_CTPROTO, .type = XTTYPE_PROTOCOL,
- .flags = XTOPT_INVERT},
- {.name = "ctorigsrc", .id = O_CTORIGSRC, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctorigdst", .id = O_CTORIGDST, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctreplsrc", .id = O_CTREPLSRC, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctrepldst", .id = O_CTREPLDST, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctstatus", .id = O_CTSTATUS, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctexpire", .id = O_CTEXPIRE, .type = XTTYPE_UINT32RC,
- .flags = XTOPT_INVERT},
- /*
- * Rev 1 and 2 only store one port, and we would normally use
- * %XTTYPE_PORT (rather than %XTTYPE_PORTRC) for that. The resulting
- * error message - in case a user passed a range nevertheless -
- * "port 22:23 resolved to nothing" is not quite as useful as using
- * %XTTYPE_PORTC and libxt_conntrack's own range test.
- */
- {.name = "ctorigsrcport", .id = O_CTORIGSRCPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT | XTOPT_NBO},
- {.name = "ctorigdstport", .id = O_CTORIGDSTPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT | XTOPT_NBO},
- {.name = "ctreplsrcport", .id = O_CTREPLSRCPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT | XTOPT_NBO},
- {.name = "ctrepldstport", .id = O_CTREPLDSTPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT | XTOPT_NBO},
- {.name = "ctdir", .id = O_CTDIR, .type = XTTYPE_STRING},
- XTOPT_TABLEEND,
- };
- #undef s
- #define s struct xt_conntrack_mtinfo3
- /* Difference from v2 is the non-NBO form. */
- static const struct xt_option_entry conntrack3_mt_opts[] = {
- {.name = "ctstate", .id = O_CTSTATE, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctproto", .id = O_CTPROTO, .type = XTTYPE_PROTOCOL,
- .flags = XTOPT_INVERT},
- {.name = "ctorigsrc", .id = O_CTORIGSRC, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctorigdst", .id = O_CTORIGDST, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctreplsrc", .id = O_CTREPLSRC, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctrepldst", .id = O_CTREPLDST, .type = XTTYPE_HOSTMASK,
- .flags = XTOPT_INVERT},
- {.name = "ctstatus", .id = O_CTSTATUS, .type = XTTYPE_STRING,
- .flags = XTOPT_INVERT},
- {.name = "ctexpire", .id = O_CTEXPIRE, .type = XTTYPE_UINT32RC,
- .flags = XTOPT_INVERT},
- {.name = "ctorigsrcport", .id = O_CTORIGSRCPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT},
- {.name = "ctorigdstport", .id = O_CTORIGDSTPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT},
- {.name = "ctreplsrcport", .id = O_CTREPLSRCPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT},
- {.name = "ctrepldstport", .id = O_CTREPLDSTPORT, .type = XTTYPE_PORTRC,
- .flags = XTOPT_INVERT},
- {.name = "ctdir", .id = O_CTDIR, .type = XTTYPE_STRING},
- XTOPT_TABLEEND,
- };
- #undef s
- static int
- parse_state(const char *state, size_t len, struct xt_conntrack_info *sinfo)
- {
- if (strncasecmp(state, "INVALID", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_INVALID;
- else if (strncasecmp(state, "NEW", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_NEW);
- else if (strncasecmp(state, "ESTABLISHED", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED);
- else if (strncasecmp(state, "RELATED", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_RELATED);
- else if (strncasecmp(state, "UNTRACKED", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_UNTRACKED;
- else if (strncasecmp(state, "SNAT", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_SNAT;
- else if (strncasecmp(state, "DNAT", len) == 0)
- sinfo->statemask |= XT_CONNTRACK_STATE_DNAT;
- else
- return 0;
- return 1;
- }
- static void
- parse_states(const char *arg, struct xt_conntrack_info *sinfo)
- {
- const char *comma;
- while ((comma = strchr(arg, ',')) != NULL) {
- if (comma == arg || !parse_state(arg, comma-arg, sinfo))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstate \"%s\"", arg);
- arg = comma+1;
- }
- if (!*arg)
- xtables_error(PARAMETER_PROBLEM, "\"--ctstate\" requires a list of "
- "states with no spaces, e.g. "
- "ESTABLISHED,RELATED");
- if (strlen(arg) == 0 || !parse_state(arg, strlen(arg), sinfo))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstate \"%s\"", arg);
- }
- static bool
- conntrack_ps_state(struct xt_conntrack_mtinfo3 *info, const char *state,
- size_t z)
- {
- if (strncasecmp(state, "INVALID", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_INVALID;
- else if (strncasecmp(state, "NEW", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_BIT(IP_CT_NEW);
- else if (strncasecmp(state, "ESTABLISHED", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED);
- else if (strncasecmp(state, "RELATED", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_BIT(IP_CT_RELATED);
- else if (strncasecmp(state, "UNTRACKED", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_UNTRACKED;
- else if (strncasecmp(state, "SNAT", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_SNAT;
- else if (strncasecmp(state, "DNAT", z) == 0)
- info->state_mask |= XT_CONNTRACK_STATE_DNAT;
- else
- return false;
- return true;
- }
- static void
- conntrack_ps_states(struct xt_conntrack_mtinfo3 *info, const char *arg)
- {
- const char *comma;
- while ((comma = strchr(arg, ',')) != NULL) {
- if (comma == arg || !conntrack_ps_state(info, arg, comma - arg))
- xtables_error(PARAMETER_PROBLEM,
- "Bad ctstate \"%s\"", arg);
- arg = comma + 1;
- }
- if (strlen(arg) == 0 || !conntrack_ps_state(info, arg, strlen(arg)))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstate \"%s\"", arg);
- }
- static int
- parse_status(const char *status, size_t len, struct xt_conntrack_info *sinfo)
- {
- if (strncasecmp(status, "NONE", len) == 0)
- sinfo->statusmask |= 0;
- else if (strncasecmp(status, "EXPECTED", len) == 0)
- sinfo->statusmask |= IPS_EXPECTED;
- else if (strncasecmp(status, "SEEN_REPLY", len) == 0)
- sinfo->statusmask |= IPS_SEEN_REPLY;
- else if (strncasecmp(status, "ASSURED", len) == 0)
- sinfo->statusmask |= IPS_ASSURED;
- #ifdef IPS_CONFIRMED
- else if (strncasecmp(status, "CONFIRMED", len) == 0)
- sinfo->statusmask |= IPS_CONFIRMED;
- #endif
- else
- return 0;
- return 1;
- }
- static void
- parse_statuses(const char *arg, struct xt_conntrack_info *sinfo)
- {
- const char *comma;
- while ((comma = strchr(arg, ',')) != NULL) {
- if (comma == arg || !parse_status(arg, comma-arg, sinfo))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstatus \"%s\"", arg);
- arg = comma+1;
- }
- if (strlen(arg) == 0 || !parse_status(arg, strlen(arg), sinfo))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstatus \"%s\"", arg);
- }
- static bool
- conntrack_ps_status(struct xt_conntrack_mtinfo3 *info, const char *status,
- size_t z)
- {
- if (strncasecmp(status, "NONE", z) == 0)
- info->status_mask |= 0;
- else if (strncasecmp(status, "EXPECTED", z) == 0)
- info->status_mask |= IPS_EXPECTED;
- else if (strncasecmp(status, "SEEN_REPLY", z) == 0)
- info->status_mask |= IPS_SEEN_REPLY;
- else if (strncasecmp(status, "ASSURED", z) == 0)
- info->status_mask |= IPS_ASSURED;
- else if (strncasecmp(status, "CONFIRMED", z) == 0)
- info->status_mask |= IPS_CONFIRMED;
- else
- return false;
- return true;
- }
- static void
- conntrack_ps_statuses(struct xt_conntrack_mtinfo3 *info, const char *arg)
- {
- const char *comma;
- while ((comma = strchr(arg, ',')) != NULL) {
- if (comma == arg || !conntrack_ps_status(info, arg, comma - arg))
- xtables_error(PARAMETER_PROBLEM,
- "Bad ctstatus \"%s\"", arg);
- arg = comma + 1;
- }
- if (strlen(arg) == 0 || !conntrack_ps_status(info, arg, strlen(arg)))
- xtables_error(PARAMETER_PROBLEM, "Bad ctstatus \"%s\"", arg);
- }
- static void conntrack_parse(struct xt_option_call *cb)
- {
- struct xt_conntrack_info *sinfo = cb->data;
- xtables_option_parse(cb);
- switch (cb->entry->id) {
- case O_CTSTATE:
- parse_states(cb->arg, sinfo);
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_STATE;
- break;
- case O_CTPROTO:
- sinfo->tuple[IP_CT_DIR_ORIGINAL].dst.protonum = cb->val.protocol;
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_PROTO;
- if (sinfo->tuple[IP_CT_DIR_ORIGINAL].dst.protonum == 0
- && (sinfo->invflags & XT_INV_PROTO))
- xtables_error(PARAMETER_PROBLEM,
- "rule would never match protocol");
- sinfo->flags |= XT_CONNTRACK_PROTO;
- break;
- case O_CTORIGSRC:
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_ORIGSRC;
- sinfo->tuple[IP_CT_DIR_ORIGINAL].src.ip = cb->val.haddr.ip;
- sinfo->flags |= XT_CONNTRACK_ORIGSRC;
- break;
- case O_CTORIGDST:
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_ORIGDST;
- sinfo->tuple[IP_CT_DIR_ORIGINAL].dst.ip = cb->val.haddr.ip;
- sinfo->flags |= XT_CONNTRACK_ORIGDST;
- break;
- case O_CTREPLSRC:
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_REPLSRC;
- sinfo->tuple[IP_CT_DIR_REPLY].src.ip = cb->val.haddr.ip;
- sinfo->flags |= XT_CONNTRACK_REPLSRC;
- break;
- case O_CTREPLDST:
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_REPLDST;
- sinfo->tuple[IP_CT_DIR_REPLY].dst.ip = cb->val.haddr.ip;
- sinfo->flags |= XT_CONNTRACK_REPLDST;
- break;
- case O_CTSTATUS:
- parse_statuses(cb->arg, sinfo);
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_STATUS;
- sinfo->flags |= XT_CONNTRACK_STATUS;
- break;
- case O_CTEXPIRE:
- sinfo->expires_min = cb->val.u32_range[0];
- sinfo->expires_max = cb->val.u32_range[0];
- if (cb->nvals >= 2)
- sinfo->expires_max = cb->val.u32_range[1];
- if (cb->invert)
- sinfo->invflags |= XT_CONNTRACK_EXPIRES;
- sinfo->flags |= XT_CONNTRACK_EXPIRES;
- break;
- }
- }
- static void conntrack_mt_parse(struct xt_option_call *cb, uint8_t rev)
- {
- struct xt_conntrack_mtinfo3 *info = cb->data;
- xtables_option_parse(cb);
- switch (cb->entry->id) {
- case O_CTSTATE:
- conntrack_ps_states(info, cb->arg);
- info->match_flags |= XT_CONNTRACK_STATE;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_STATE;
- break;
- case O_CTPROTO:
- info->l4proto = cb->val.protocol;
- if (info->l4proto == 0 && (info->invert_flags & XT_INV_PROTO))
- xtables_error(PARAMETER_PROBLEM, "conntrack: rule would "
- "never match protocol");
- info->match_flags |= XT_CONNTRACK_PROTO;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_PROTO;
- break;
- case O_CTORIGSRC:
- info->origsrc_addr = cb->val.haddr;
- info->origsrc_mask = cb->val.hmask;
- info->match_flags |= XT_CONNTRACK_ORIGSRC;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_ORIGSRC;
- break;
- case O_CTORIGDST:
- info->origdst_addr = cb->val.haddr;
- info->origdst_mask = cb->val.hmask;
- info->match_flags |= XT_CONNTRACK_ORIGDST;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_ORIGDST;
- break;
- case O_CTREPLSRC:
- info->replsrc_addr = cb->val.haddr;
- info->replsrc_mask = cb->val.hmask;
- info->match_flags |= XT_CONNTRACK_REPLSRC;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_REPLSRC;
- break;
- case O_CTREPLDST:
- info->repldst_addr = cb->val.haddr;
- info->repldst_mask = cb->val.hmask;
- info->match_flags |= XT_CONNTRACK_REPLDST;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_REPLDST;
- break;
- case O_CTSTATUS:
- conntrack_ps_statuses(info, cb->arg);
- info->match_flags |= XT_CONNTRACK_STATUS;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_STATUS;
- break;
- case O_CTEXPIRE:
- info->expires_min = cb->val.u32_range[0];
- info->expires_max = cb->val.u32_range[0];
- if (cb->nvals >= 2)
- info->expires_max = cb->val.u32_range[1];
- info->match_flags |= XT_CONNTRACK_EXPIRES;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_EXPIRES;
- break;
- case O_CTORIGSRCPORT:
- info->origsrc_port = cb->val.port_range[0];
- info->origsrc_port_high = cb->val.port_range[cb->nvals >= 2];
- info->match_flags |= XT_CONNTRACK_ORIGSRC_PORT;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_ORIGSRC_PORT;
- break;
- case O_CTORIGDSTPORT:
- info->origdst_port = cb->val.port_range[0];
- info->origdst_port_high = cb->val.port_range[cb->nvals >= 2];
- info->match_flags |= XT_CONNTRACK_ORIGDST_PORT;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_ORIGDST_PORT;
- break;
- case O_CTREPLSRCPORT:
- info->replsrc_port = cb->val.port_range[0];
- info->replsrc_port_high = cb->val.port_range[cb->nvals >= 2];
- info->match_flags |= XT_CONNTRACK_REPLSRC_PORT;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_REPLSRC_PORT;
- break;
- case O_CTREPLDSTPORT:
- info->repldst_port = cb->val.port_range[0];
- info->repldst_port_high = cb->val.port_range[cb->nvals >= 2];
- info->match_flags |= XT_CONNTRACK_REPLDST_PORT;
- if (cb->invert)
- info->invert_flags |= XT_CONNTRACK_REPLDST_PORT;
- break;
- case O_CTDIR:
- if (strcasecmp(cb->arg, "ORIGINAL") == 0) {
- info->match_flags |= XT_CONNTRACK_DIRECTION;
- info->invert_flags &= ~XT_CONNTRACK_DIRECTION;
- } else if (strcasecmp(cb->arg, "REPLY") == 0) {
- info->match_flags |= XT_CONNTRACK_DIRECTION;
- info->invert_flags |= XT_CONNTRACK_DIRECTION;
- } else {
- xtables_param_act(XTF_BAD_VALUE, "conntrack", "--ctdir", cb->arg);
- }
- break;
- }
- }
- #define cinfo_transform(r, l) \
- do { \
- memcpy((r), (l), offsetof(typeof(*(l)), state_mask)); \
- (r)->state_mask = (l)->state_mask; \
- (r)->status_mask = (l)->status_mask; \
- } while (false);
- static void conntrack1_mt_parse(struct xt_option_call *cb)
- {
- struct xt_conntrack_mtinfo1 *info = cb->data;
- struct xt_conntrack_mtinfo3 up;
- memset(&up, 0, sizeof(up));
- cinfo_transform(&up, info);
- up.origsrc_port_high = up.origsrc_port;
- up.origdst_port_high = up.origdst_port;
- up.replsrc_port_high = up.replsrc_port;
- up.repldst_port_high = up.repldst_port;
- cb->data = &up;
- conntrack_mt_parse(cb, 3);
- if (up.origsrc_port != up.origsrc_port_high ||
- up.origdst_port != up.origdst_port_high ||
- up.replsrc_port != up.replsrc_port_high ||
- up.repldst_port != up.repldst_port_high)
- xtables_error(PARAMETER_PROBLEM,
- "conntrack rev 1 does not support port ranges");
- cinfo_transform(info, &up);
- cb->data = info;
- }
- static void conntrack2_mt_parse(struct xt_option_call *cb)
- {
- #define cinfo2_transform(r, l) \
- memcpy((r), (l), offsetof(typeof(*(l)), sizeof(*info));
- struct xt_conntrack_mtinfo2 *info = cb->data;
- struct xt_conntrack_mtinfo3 up;
- memset(&up, 0, sizeof(up));
- memcpy(&up, info, sizeof(*info));
- up.origsrc_port_high = up.origsrc_port;
- up.origdst_port_high = up.origdst_port;
- up.replsrc_port_high = up.replsrc_port;
- up.repldst_port_high = up.repldst_port;
- cb->data = &up;
- conntrack_mt_parse(cb, 3);
- if (up.origsrc_port != up.origsrc_port_high ||
- up.origdst_port != up.origdst_port_high ||
- up.replsrc_port != up.replsrc_port_high ||
- up.repldst_port != up.repldst_port_high)
- xtables_error(PARAMETER_PROBLEM,
- "conntrack rev 2 does not support port ranges");
- memcpy(info, &up, sizeof(*info));
- cb->data = info;
- #undef cinfo2_transform
- }
- static void conntrack3_mt_parse(struct xt_option_call *cb)
- {
- conntrack_mt_parse(cb, 3);
- }
- static void conntrack_mt_check(struct xt_fcheck_call *cb)
- {
- if (cb->xflags == 0)
- xtables_error(PARAMETER_PROBLEM, "conntrack: At least one option "
- "is required");
- }
- static void
- print_state(unsigned int statemask)
- {
- const char *sep = " ";
- if (statemask & XT_CONNTRACK_STATE_INVALID) {
- printf("%sINVALID", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_NEW)) {
- printf("%sNEW", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_RELATED)) {
- printf("%sRELATED", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED)) {
- printf("%sESTABLISHED", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_UNTRACKED) {
- printf("%sUNTRACKED", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_SNAT) {
- printf("%sSNAT", sep);
- sep = ",";
- }
- if (statemask & XT_CONNTRACK_STATE_DNAT) {
- printf("%sDNAT", sep);
- sep = ",";
- }
- }
- static void
- print_status(unsigned int statusmask)
- {
- const char *sep = " ";
- if (statusmask & IPS_EXPECTED) {
- printf("%sEXPECTED", sep);
- sep = ",";
- }
- if (statusmask & IPS_SEEN_REPLY) {
- printf("%sSEEN_REPLY", sep);
- sep = ",";
- }
- if (statusmask & IPS_ASSURED) {
- printf("%sASSURED", sep);
- sep = ",";
- }
- if (statusmask & IPS_CONFIRMED) {
- printf("%sCONFIRMED", sep);
- sep = ",";
- }
- if (statusmask == 0)
- printf("%sNONE", sep);
- }
- static void
- conntrack_dump_addr(const union nf_inet_addr *addr,
- const union nf_inet_addr *mask,
- unsigned int family, bool numeric)
- {
- if (family == NFPROTO_IPV4) {
- if (!numeric && addr->ip == 0) {
- printf(" anywhere");
- return;
- }
- if (numeric)
- printf(" %s%s",
- xtables_ipaddr_to_numeric(&addr->in),
- xtables_ipmask_to_numeric(&mask->in));
- else
- printf(" %s%s",
- xtables_ipaddr_to_anyname(&addr->in),
- xtables_ipmask_to_numeric(&mask->in));
- } else if (family == NFPROTO_IPV6) {
- if (!numeric && addr->ip6[0] == 0 && addr->ip6[1] == 0 &&
- addr->ip6[2] == 0 && addr->ip6[3] == 0) {
- printf(" anywhere");
- return;
- }
- if (numeric)
- printf(" %s%s",
- xtables_ip6addr_to_numeric(&addr->in6),
- xtables_ip6mask_to_numeric(&mask->in6));
- else
- printf(" %s%s",
- xtables_ip6addr_to_anyname(&addr->in6),
- xtables_ip6mask_to_numeric(&mask->in6));
- }
- }
- static void
- print_addr(const struct in_addr *addr, const struct in_addr *mask,
- int inv, int numeric)
- {
- char buf[BUFSIZ];
- if (inv)
- printf(" !");
- if (mask->s_addr == 0L && !numeric)
- printf(" %s", "anywhere");
- else {
- if (numeric)
- strcpy(buf, xtables_ipaddr_to_numeric(addr));
- else
- strcpy(buf, xtables_ipaddr_to_anyname(addr));
- strcat(buf, xtables_ipmask_to_numeric(mask));
- printf(" %s", buf);
- }
- }
- static void
- matchinfo_print(const void *ip, const struct xt_entry_match *match, int numeric, const char *optpfx)
- {
- const struct xt_conntrack_info *sinfo = (const void *)match->data;
- if(sinfo->flags & XT_CONNTRACK_STATE) {
- if (sinfo->invflags & XT_CONNTRACK_STATE)
- printf(" !");
- printf(" %sctstate", optpfx);
- print_state(sinfo->statemask);
- }
- if(sinfo->flags & XT_CONNTRACK_PROTO) {
- if (sinfo->invflags & XT_CONNTRACK_PROTO)
- printf(" !");
- printf(" %sctproto", optpfx);
- printf(" %u", sinfo->tuple[IP_CT_DIR_ORIGINAL].dst.protonum);
- }
- if(sinfo->flags & XT_CONNTRACK_ORIGSRC) {
- if (sinfo->invflags & XT_CONNTRACK_ORIGSRC)
- printf(" !");
- printf(" %sctorigsrc", optpfx);
- print_addr(
- (struct in_addr *)&sinfo->tuple[IP_CT_DIR_ORIGINAL].src.ip,
- &sinfo->sipmsk[IP_CT_DIR_ORIGINAL],
- false,
- numeric);
- }
- if(sinfo->flags & XT_CONNTRACK_ORIGDST) {
- if (sinfo->invflags & XT_CONNTRACK_ORIGDST)
- printf(" !");
- printf(" %sctorigdst", optpfx);
- print_addr(
- (struct in_addr *)&sinfo->tuple[IP_CT_DIR_ORIGINAL].dst.ip,
- &sinfo->dipmsk[IP_CT_DIR_ORIGINAL],
- false,
- numeric);
- }
- if(sinfo->flags & XT_CONNTRACK_REPLSRC) {
- if (sinfo->invflags & XT_CONNTRACK_REPLSRC)
- printf(" !");
- printf(" %sctreplsrc", optpfx);
- print_addr(
- (struct in_addr *)&sinfo->tuple[IP_CT_DIR_REPLY].src.ip,
- &sinfo->sipmsk[IP_CT_DIR_REPLY],
- false,
- numeric);
- }
- if(sinfo->flags & XT_CONNTRACK_REPLDST) {
- if (sinfo->invflags & XT_CONNTRACK_REPLDST)
- printf(" !");
- printf(" %sctrepldst", optpfx);
- print_addr(
- (struct in_addr *)&sinfo->tuple[IP_CT_DIR_REPLY].dst.ip,
- &sinfo->dipmsk[IP_CT_DIR_REPLY],
- false,
- numeric);
- }
- if(sinfo->flags & XT_CONNTRACK_STATUS) {
- if (sinfo->invflags & XT_CONNTRACK_STATUS)
- printf(" !");
- printf(" %sctstatus", optpfx);
- print_status(sinfo->statusmask);
- }
- if(sinfo->flags & XT_CONNTRACK_EXPIRES) {
- if (sinfo->invflags & XT_CONNTRACK_EXPIRES)
- printf(" !");
- printf(" %sctexpire ", optpfx);
- if (sinfo->expires_max == sinfo->expires_min)
- printf("%lu", sinfo->expires_min);
- else
- printf("%lu:%lu", sinfo->expires_min, sinfo->expires_max);
- }
- if (sinfo->flags & XT_CONNTRACK_DIRECTION) {
- if (sinfo->invflags & XT_CONNTRACK_DIRECTION)
- printf(" %sctdir REPLY", optpfx);
- else
- printf(" %sctdir ORIGINAL", optpfx);
- }
- }
- static void
- conntrack_dump_ports(const char *prefix, const char *opt,
- u_int16_t port_low, u_int16_t port_high)
- {
- if (port_high == 0 || port_low == port_high)
- printf(" %s%s %u", prefix, opt, port_low);
- else
- printf(" %s%s %u:%u", prefix, opt, port_low, port_high);
- }
- static void
- conntrack_dump(const struct xt_conntrack_mtinfo3 *info, const char *prefix,
- unsigned int family, bool numeric, bool v3)
- {
- if (info->match_flags & XT_CONNTRACK_STATE) {
- if (info->invert_flags & XT_CONNTRACK_STATE)
- printf(" !");
- printf(" %s%s", prefix,
- info->match_flags & XT_CONNTRACK_STATE_ALIAS
- ? "state" : "ctstate");
- print_state(info->state_mask);
- }
- if (info->match_flags & XT_CONNTRACK_PROTO) {
- if (info->invert_flags & XT_CONNTRACK_PROTO)
- printf(" !");
- printf(" %sctproto %u", prefix, info->l4proto);
- }
- if (info->match_flags & XT_CONNTRACK_ORIGSRC) {
- if (info->invert_flags & XT_CONNTRACK_ORIGSRC)
- printf(" !");
- printf(" %sctorigsrc", prefix);
- conntrack_dump_addr(&info->origsrc_addr, &info->origsrc_mask,
- family, numeric);
- }
- if (info->match_flags & XT_CONNTRACK_ORIGDST) {
- if (info->invert_flags & XT_CONNTRACK_ORIGDST)
- printf(" !");
- printf(" %sctorigdst", prefix);
- conntrack_dump_addr(&info->origdst_addr, &info->origdst_mask,
- family, numeric);
- }
- if (info->match_flags & XT_CONNTRACK_REPLSRC) {
- if (info->invert_flags & XT_CONNTRACK_REPLSRC)
- printf(" !");
- printf(" %sctreplsrc", prefix);
- conntrack_dump_addr(&info->replsrc_addr, &info->replsrc_mask,
- family, numeric);
- }
- if (info->match_flags & XT_CONNTRACK_REPLDST) {
- if (info->invert_flags & XT_CONNTRACK_REPLDST)
- printf(" !");
- printf(" %sctrepldst", prefix);
- conntrack_dump_addr(&info->repldst_addr, &info->repldst_mask,
- family, numeric);
- }
- if (info->match_flags & XT_CONNTRACK_ORIGSRC_PORT) {
- if (info->invert_flags & XT_CONNTRACK_ORIGSRC_PORT)
- printf(" !");
- conntrack_dump_ports(prefix, "ctorigsrcport",
- v3 ? info->origsrc_port : ntohs(info->origsrc_port),
- v3 ? info->origsrc_port_high : 0);
- }
- if (info->match_flags & XT_CONNTRACK_ORIGDST_PORT) {
- if (info->invert_flags & XT_CONNTRACK_ORIGDST_PORT)
- printf(" !");
- conntrack_dump_ports(prefix, "ctorigdstport",
- v3 ? info->origdst_port : ntohs(info->origdst_port),
- v3 ? info->origdst_port_high : 0);
- }
- if (info->match_flags & XT_CONNTRACK_REPLSRC_PORT) {
- if (info->invert_flags & XT_CONNTRACK_REPLSRC_PORT)
- printf(" !");
- conntrack_dump_ports(prefix, "ctreplsrcport",
- v3 ? info->replsrc_port : ntohs(info->replsrc_port),
- v3 ? info->replsrc_port_high : 0);
- }
- if (info->match_flags & XT_CONNTRACK_REPLDST_PORT) {
- if (info->invert_flags & XT_CONNTRACK_REPLDST_PORT)
- printf(" !");
- conntrack_dump_ports(prefix, "ctrepldstport",
- v3 ? info->repldst_port : ntohs(info->repldst_port),
- v3 ? info->repldst_port_high : 0);
- }
- if (info->match_flags & XT_CONNTRACK_STATUS) {
- if (info->invert_flags & XT_CONNTRACK_STATUS)
- printf(" !");
- printf(" %sctstatus", prefix);
- print_status(info->status_mask);
- }
- if (info->match_flags & XT_CONNTRACK_EXPIRES) {
- if (info->invert_flags & XT_CONNTRACK_EXPIRES)
- printf(" !");
- printf(" %sctexpire ", prefix);
- if (info->expires_max == info->expires_min)
- printf("%u", (unsigned int)info->expires_min);
- else
- printf("%u:%u", (unsigned int)info->expires_min,
- (unsigned int)info->expires_max);
- }
- if (info->match_flags & XT_CONNTRACK_DIRECTION) {
- if (info->invert_flags & XT_CONNTRACK_DIRECTION)
- printf(" %sctdir REPLY", prefix);
- else
- printf(" %sctdir ORIGINAL", prefix);
- }
- }
- static const char *
- conntrack_print_name_alias(const struct xt_entry_match *match)
- {
- struct xt_conntrack_mtinfo1 *info = (void *)match->data;
- return info->match_flags & XT_CONNTRACK_STATE_ALIAS
- ? "state" : "conntrack";
- }
- static void conntrack_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- matchinfo_print(ip, match, numeric, "");
- }
- static void
- conntrack1_mt4_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- const struct xt_conntrack_mtinfo1 *info = (void *)match->data;
- struct xt_conntrack_mtinfo3 up;
- cinfo_transform(&up, info);
- conntrack_dump(&up, "", NFPROTO_IPV4, numeric, false);
- }
- static void
- conntrack1_mt6_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- const struct xt_conntrack_mtinfo1 *info = (void *)match->data;
- struct xt_conntrack_mtinfo3 up;
- cinfo_transform(&up, info);
- conntrack_dump(&up, "", NFPROTO_IPV6, numeric, false);
- }
- static void
- conntrack2_mt_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- conntrack_dump((const void *)match->data, "", NFPROTO_IPV4, numeric, false);
- }
- static void
- conntrack2_mt6_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- conntrack_dump((const void *)match->data, "", NFPROTO_IPV6, numeric, false);
- }
- static void
- conntrack3_mt_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- conntrack_dump((const void *)match->data, "", NFPROTO_IPV4, numeric, true);
- }
- static void
- conntrack3_mt6_print(const void *ip, const struct xt_entry_match *match,
- int numeric)
- {
- conntrack_dump((const void *)match->data, "", NFPROTO_IPV6, numeric, true);
- }
- static void conntrack_save(const void *ip, const struct xt_entry_match *match)
- {
- matchinfo_print(ip, match, 1, "--");
- }
- static void conntrack3_mt_save(const void *ip,
- const struct xt_entry_match *match)
- {
- conntrack_dump((const void *)match->data, "--", NFPROTO_IPV4, true, true);
- }
- static void conntrack3_mt6_save(const void *ip,
- const struct xt_entry_match *match)
- {
- conntrack_dump((const void *)match->data, "--", NFPROTO_IPV6, true, true);
- }
- static void conntrack2_mt_save(const void *ip,
- const struct xt_entry_match *match)
- {
- conntrack_dump((const void *)match->data, "--", NFPROTO_IPV4, true, false);
- }
- static void conntrack2_mt6_save(const void *ip,
- const struct xt_entry_match *match)
- {
- conntrack_dump((const void *)match->data, "--", NFPROTO_IPV6, true, false);
- }
- static void
- conntrack1_mt4_save(const void *ip, const struct xt_entry_match *match)
- {
- const struct xt_conntrack_mtinfo1 *info = (void *)match->data;
- struct xt_conntrack_mtinfo3 up;
- cinfo_transform(&up, info);
- conntrack_dump(&up, "--", NFPROTO_IPV4, true, false);
- }
- static void
- conntrack1_mt6_save(const void *ip, const struct xt_entry_match *match)
- {
- const struct xt_conntrack_mtinfo1 *info = (void *)match->data;
- struct xt_conntrack_mtinfo3 up;
- cinfo_transform(&up, info);
- conntrack_dump(&up, "--", NFPROTO_IPV6, true, false);
- }
- static void
- state_help(void)
- {
- printf(
- "state match options:\n"
- " [!] --state [INVALID|ESTABLISHED|NEW|RELATED|UNTRACKED][,...]\n"
- " State(s) to match\n");
- }
- static const struct xt_option_entry state_opts[] = {
- {.name = "state", .id = O_CTSTATE, .type = XTTYPE_STRING,
- .flags = XTOPT_MAND | XTOPT_INVERT},
- XTOPT_TABLEEND,
- };
- static unsigned int
- state_parse_state(const char *state, size_t len)
- {
- if (strncasecmp(state, "INVALID", len) == 0)
- return XT_STATE_INVALID;
- else if (strncasecmp(state, "NEW", len) == 0)
- return XT_STATE_BIT(IP_CT_NEW);
- else if (strncasecmp(state, "ESTABLISHED", len) == 0)
- return XT_STATE_BIT(IP_CT_ESTABLISHED);
- else if (strncasecmp(state, "RELATED", len) == 0)
- return XT_STATE_BIT(IP_CT_RELATED);
- else if (strncasecmp(state, "UNTRACKED", len) == 0)
- return XT_STATE_UNTRACKED;
- return 0;
- }
- static unsigned int
- state_parse_states(const char *arg)
- {
- const char *comma;
- unsigned int mask = 0, flag;
- while ((comma = strchr(arg, ',')) != NULL) {
- if (comma == arg)
- goto badstate;
- flag = state_parse_state(arg, comma-arg);
- if (flag == 0)
- goto badstate;
- mask |= flag;
- arg = comma+1;
- }
- if (!*arg)
- xtables_error(PARAMETER_PROBLEM, "\"--state\" requires a list of "
- "states with no spaces, e.g. "
- "ESTABLISHED,RELATED");
- if (strlen(arg) == 0)
- goto badstate;
- flag = state_parse_state(arg, strlen(arg));
- if (flag == 0)
- goto badstate;
- mask |= flag;
- return mask;
- badstate:
- xtables_error(PARAMETER_PROBLEM, "Bad state \"%s\"", arg);
- }
- static void state_parse(struct xt_option_call *cb)
- {
- struct xt_state_info *sinfo = cb->data;
- xtables_option_parse(cb);
- sinfo->statemask = state_parse_states(cb->arg);
- if (cb->invert)
- sinfo->statemask = ~sinfo->statemask;
- }
- static void state_ct1_parse(struct xt_option_call *cb)
- {
- struct xt_conntrack_mtinfo1 *sinfo = cb->data;
- xtables_option_parse(cb);
- sinfo->match_flags = XT_CONNTRACK_STATE | XT_CONNTRACK_STATE_ALIAS;
- sinfo->state_mask = state_parse_states(cb->arg);
- if (cb->invert)
- sinfo->invert_flags |= XT_CONNTRACK_STATE;
- }
- static void state_ct23_parse(struct xt_option_call *cb)
- {
- struct xt_conntrack_mtinfo3 *sinfo = cb->data;
- xtables_option_parse(cb);
- sinfo->match_flags = XT_CONNTRACK_STATE | XT_CONNTRACK_STATE_ALIAS;
- sinfo->state_mask = state_parse_states(cb->arg);
- if (cb->invert)
- sinfo->invert_flags |= XT_CONNTRACK_STATE;
- }
- static void state_print_state(unsigned int statemask)
- {
- const char *sep = "";
- if (statemask & XT_STATE_INVALID) {
- printf("%sINVALID", sep);
- sep = ",";
- }
- if (statemask & XT_STATE_BIT(IP_CT_NEW)) {
- printf("%sNEW", sep);
- sep = ",";
- }
- if (statemask & XT_STATE_BIT(IP_CT_RELATED)) {
- printf("%sRELATED", sep);
- sep = ",";
- }
- if (statemask & XT_STATE_BIT(IP_CT_ESTABLISHED)) {
- printf("%sESTABLISHED", sep);
- sep = ",";
- }
- if (statemask & XT_STATE_UNTRACKED) {
- printf("%sUNTRACKED", sep);
- sep = ",";
- }
- }
- static void
- state_print(const void *ip,
- const struct xt_entry_match *match,
- int numeric)
- {
- const struct xt_state_info *sinfo = (const void *)match->data;
- printf(" state ");
- state_print_state(sinfo->statemask);
- }
- static void state_save(const void *ip, const struct xt_entry_match *match)
- {
- const struct xt_state_info *sinfo = (const void *)match->data;
- printf(" --state ");
- state_print_state(sinfo->statemask);
- }
- static struct xtables_match conntrack_mt_reg[] = {
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 0,
- .family = NFPROTO_IPV4,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_info)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_info)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack_print,
- .save = conntrack_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack_mt_opts_v0,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 1,
- .family = NFPROTO_IPV4,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack1_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack1_mt4_print,
- .save = conntrack1_mt4_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack2_mt_opts,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 1,
- .family = NFPROTO_IPV6,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack1_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack1_mt6_print,
- .save = conntrack1_mt6_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack2_mt_opts,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 2,
- .family = NFPROTO_IPV4,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack2_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack2_mt_print,
- .save = conntrack2_mt_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack2_mt_opts,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 2,
- .family = NFPROTO_IPV6,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack2_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack2_mt6_print,
- .save = conntrack2_mt6_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack2_mt_opts,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 3,
- .family = NFPROTO_IPV4,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack3_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack3_mt_print,
- .save = conntrack3_mt_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack3_mt_opts,
- },
- {
- .version = XTABLES_VERSION,
- .name = "conntrack",
- .revision = 3,
- .family = NFPROTO_IPV6,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .help = conntrack_mt_help,
- .x6_parse = conntrack3_mt_parse,
- .x6_fcheck = conntrack_mt_check,
- .print = conntrack3_mt6_print,
- .save = conntrack3_mt6_save,
- .alias = conntrack_print_name_alias,
- .x6_options = conntrack3_mt_opts,
- },
- {
- .family = NFPROTO_UNSPEC,
- .name = "state",
- .real_name = "conntrack",
- .revision = 1,
- .ext_flags = XTABLES_EXT_ALIAS,
- .version = XTABLES_VERSION,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo1)),
- .help = state_help,
- .x6_parse = state_ct1_parse,
- .x6_options = state_opts,
- },
- {
- .family = NFPROTO_UNSPEC,
- .name = "state",
- .real_name = "conntrack",
- .revision = 2,
- .ext_flags = XTABLES_EXT_ALIAS,
- .version = XTABLES_VERSION,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo2)),
- .help = state_help,
- .x6_parse = state_ct23_parse,
- .x6_options = state_opts,
- },
- {
- .family = NFPROTO_UNSPEC,
- .name = "state",
- .real_name = "conntrack",
- .revision = 3,
- .ext_flags = XTABLES_EXT_ALIAS,
- .version = XTABLES_VERSION,
- .size = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_conntrack_mtinfo3)),
- .help = state_help,
- .x6_parse = state_ct23_parse,
- .x6_options = state_opts,
- },
- {
- .family = NFPROTO_UNSPEC,
- .name = "state",
- .revision = 0,
- .version = XTABLES_VERSION,
- .size = XT_ALIGN(sizeof(struct xt_state_info)),
- .userspacesize = XT_ALIGN(sizeof(struct xt_state_info)),
- .help = state_help,
- .print = state_print,
- .save = state_save,
- .x6_parse = state_parse,
- .x6_options = state_opts,
- },
- };
- void _init(void)
- {
- xtables_register_matches(conntrack_mt_reg, ARRAY_SIZE(conntrack_mt_reg));
- }
|