2 * Copyright 2005, Gleb Smirnoff <glebius@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/ctype.h>
35 #include <sys/errno.h>
36 #include <sys/syslog.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/in.h>
40 #include <netinet/ip.h>
41 #include <netinet/ip_var.h>
42 #include <netinet/tcp.h>
43 #include <machine/in_cksum.h>
45 #include <netinet/libalias/alias.h>
46 #include <netinet/libalias/alias_local.h>
48 #include <netgraph/ng_message.h>
49 #include <netgraph/ng_parse.h>
50 #include <netgraph/ng_nat.h>
51 #include <netgraph/netgraph.h>
53 static ng_constructor_t ng_nat_constructor;
54 static ng_rcvmsg_t ng_nat_rcvmsg;
55 static ng_shutdown_t ng_nat_shutdown;
56 static ng_newhook_t ng_nat_newhook;
57 static ng_rcvdata_t ng_nat_rcvdata;
58 static ng_disconnect_t ng_nat_disconnect;
60 static unsigned int ng_nat_translate_flags(unsigned int x);
62 /* Parse type for struct ng_nat_mode. */
63 static const struct ng_parse_struct_field ng_nat_mode_fields[]
65 static const struct ng_parse_type ng_nat_mode_type = {
66 &ng_parse_struct_type,
70 /* Parse type for 'description' field in structs. */
71 static const struct ng_parse_fixedstring_info ng_nat_description_info
72 = { NG_NAT_DESC_LENGTH };
73 static const struct ng_parse_type ng_nat_description_type = {
74 &ng_parse_fixedstring_type,
75 &ng_nat_description_info
78 /* Parse type for struct ng_nat_redirect_port. */
79 static const struct ng_parse_struct_field ng_nat_redirect_port_fields[]
80 = NG_NAT_REDIRECT_PORT_TYPE_INFO(&ng_nat_description_type);
81 static const struct ng_parse_type ng_nat_redirect_port_type = {
82 &ng_parse_struct_type,
83 &ng_nat_redirect_port_fields
86 /* Parse type for struct ng_nat_redirect_addr. */
87 static const struct ng_parse_struct_field ng_nat_redirect_addr_fields[]
88 = NG_NAT_REDIRECT_ADDR_TYPE_INFO(&ng_nat_description_type);
89 static const struct ng_parse_type ng_nat_redirect_addr_type = {
90 &ng_parse_struct_type,
91 &ng_nat_redirect_addr_fields
94 /* Parse type for struct ng_nat_redirect_proto. */
95 static const struct ng_parse_struct_field ng_nat_redirect_proto_fields[]
96 = NG_NAT_REDIRECT_PROTO_TYPE_INFO(&ng_nat_description_type);
97 static const struct ng_parse_type ng_nat_redirect_proto_type = {
98 &ng_parse_struct_type,
99 &ng_nat_redirect_proto_fields
102 /* Parse type for struct ng_nat_add_server. */
103 static const struct ng_parse_struct_field ng_nat_add_server_fields[]
104 = NG_NAT_ADD_SERVER_TYPE_INFO;
105 static const struct ng_parse_type ng_nat_add_server_type = {
106 &ng_parse_struct_type,
107 &ng_nat_add_server_fields
110 /* Parse type for one struct ng_nat_listrdrs_entry. */
111 static const struct ng_parse_struct_field ng_nat_listrdrs_entry_fields[]
112 = NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(&ng_nat_description_type);
113 static const struct ng_parse_type ng_nat_listrdrs_entry_type = {
114 &ng_parse_struct_type,
115 &ng_nat_listrdrs_entry_fields
118 /* Parse type for 'redirects' array in struct ng_nat_list_redirects. */
120 ng_nat_listrdrs_ary_getLength(const struct ng_parse_type *type,
121 const u_char *start, const u_char *buf)
123 const struct ng_nat_list_redirects *lr;
125 lr = (const struct ng_nat_list_redirects *)
126 (buf - offsetof(struct ng_nat_list_redirects, redirects));
127 return lr->total_count;
130 static const struct ng_parse_array_info ng_nat_listrdrs_ary_info = {
131 &ng_nat_listrdrs_entry_type,
132 &ng_nat_listrdrs_ary_getLength,
135 static const struct ng_parse_type ng_nat_listrdrs_ary_type = {
136 &ng_parse_array_type,
137 &ng_nat_listrdrs_ary_info
140 /* Parse type for struct ng_nat_list_redirects. */
141 static const struct ng_parse_struct_field ng_nat_list_redirects_fields[]
142 = NG_NAT_LIST_REDIRECTS_TYPE_INFO(&ng_nat_listrdrs_ary_type);
143 static const struct ng_parse_type ng_nat_list_redirects_type = {
144 &ng_parse_struct_type,
145 &ng_nat_list_redirects_fields
148 /* Parse type for struct ng_nat_libalias_info. */
149 static const struct ng_parse_struct_field ng_nat_libalias_info_fields[]
150 = NG_NAT_LIBALIAS_INFO;
151 static const struct ng_parse_type ng_nat_libalias_info_type = {
152 &ng_parse_struct_type,
153 &ng_nat_libalias_info_fields
156 /* List of commands and how to convert arguments to/from ASCII. */
157 static const struct ng_cmdlist ng_nat_cmdlist[] = {
162 &ng_parse_ipaddr_type,
176 &ng_parse_ipaddr_type,
181 NGM_NAT_REDIRECT_PORT,
183 &ng_nat_redirect_port_type,
184 &ng_parse_uint32_type
188 NGM_NAT_REDIRECT_ADDR,
190 &ng_nat_redirect_addr_type,
191 &ng_parse_uint32_type
195 NGM_NAT_REDIRECT_PROTO,
197 &ng_nat_redirect_proto_type,
198 &ng_parse_uint32_type
202 NGM_NAT_REDIRECT_DYNAMIC,
204 &ng_parse_uint32_type,
209 NGM_NAT_REDIRECT_DELETE,
211 &ng_parse_uint32_type,
218 &ng_nat_add_server_type,
223 NGM_NAT_LIST_REDIRECTS,
226 &ng_nat_list_redirects_type
232 &ng_parse_string_type,
237 NGM_NAT_LIBALIAS_INFO,
240 &ng_nat_libalias_info_type
245 /* Netgraph node type descriptor. */
246 static struct ng_type typestruct = {
247 .version = NG_ABI_VERSION,
248 .name = NG_NAT_NODE_TYPE,
249 .constructor = ng_nat_constructor,
250 .rcvmsg = ng_nat_rcvmsg,
251 .shutdown = ng_nat_shutdown,
252 .newhook = ng_nat_newhook,
253 .rcvdata = ng_nat_rcvdata,
254 .disconnect = ng_nat_disconnect,
255 .cmdlist = ng_nat_cmdlist,
257 NETGRAPH_INIT(nat, &typestruct);
258 MODULE_DEPEND(ng_nat, libalias, 1, 1, 1);
260 /* Element for list of redirects. */
261 struct ng_nat_rdr_lst {
262 STAILQ_ENTRY(ng_nat_rdr_lst) entries;
263 struct alias_link *lnk;
264 struct ng_nat_listrdrs_entry rdr;
266 STAILQ_HEAD(rdrhead, ng_nat_rdr_lst);
268 /* Information we store for each node. */
270 node_p node; /* back pointer to node */
271 hook_p in; /* hook for demasquerading */
272 hook_p out; /* hook for masquerading */
273 struct libalias *lib; /* libalias handler */
274 uint32_t flags; /* status flags */
275 uint32_t rdrcount; /* number or redirects in list */
276 uint32_t nextid; /* for next in turn in list */
277 struct rdrhead redirhead; /* redirect list header */
279 typedef struct ng_nat_priv *priv_p;
281 /* Values of flags */
282 #define NGNAT_CONNECTED 0x1 /* We have both hooks connected */
283 #define NGNAT_ADDR_DEFINED 0x2 /* NGM_NAT_SET_IPADDR happened */
286 ng_nat_constructor(node_p node)
290 /* Initialize private descriptor. */
291 priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO);
293 /* Init aliasing engine. */
294 priv->lib = LibAliasInit(NULL);
296 /* Set same ports on. */
297 (void )LibAliasSetMode(priv->lib, PKT_ALIAS_SAME_PORTS,
298 PKT_ALIAS_SAME_PORTS);
300 /* Init redirects housekeeping. */
303 STAILQ_INIT(&priv->redirhead);
305 /* Link structs together. */
306 NG_NODE_SET_PRIVATE(node, priv);
310 * libalias is not thread safe, so our node
311 * must be single threaded.
313 NG_NODE_FORCE_WRITER(node);
319 ng_nat_newhook(node_p node, hook_p hook, const char *name)
321 const priv_p priv = NG_NODE_PRIVATE(node);
323 if (strcmp(name, NG_NAT_HOOK_IN) == 0) {
325 } else if (strcmp(name, NG_NAT_HOOK_OUT) == 0) {
330 if (priv->out != NULL &&
332 priv->flags |= NGNAT_CONNECTED;
338 ng_nat_rcvmsg(node_p node, item_p item, hook_p lasthook)
340 const priv_p priv = NG_NODE_PRIVATE(node);
341 struct ng_mesg *resp = NULL;
345 NGI_GET_MSG(item, msg);
347 switch (msg->header.typecookie) {
349 switch (msg->header.cmd) {
350 case NGM_NAT_SET_IPADDR:
352 struct in_addr *const ia = (struct in_addr *)msg->data;
354 if (msg->header.arglen < sizeof(*ia)) {
359 LibAliasSetAddress(priv->lib, *ia);
361 priv->flags |= NGNAT_ADDR_DEFINED;
364 case NGM_NAT_SET_MODE:
366 struct ng_nat_mode *const mode =
367 (struct ng_nat_mode *)msg->data;
369 if (msg->header.arglen < sizeof(*mode)) {
374 if (LibAliasSetMode(priv->lib,
375 ng_nat_translate_flags(mode->flags),
376 ng_nat_translate_flags(mode->mask)) < 0) {
382 case NGM_NAT_SET_TARGET:
384 struct in_addr *const ia = (struct in_addr *)msg->data;
386 if (msg->header.arglen < sizeof(*ia)) {
391 LibAliasSetTarget(priv->lib, *ia);
394 case NGM_NAT_REDIRECT_PORT:
396 struct ng_nat_rdr_lst *entry;
397 struct ng_nat_redirect_port *const rp =
398 (struct ng_nat_redirect_port *)msg->data;
400 if (msg->header.arglen < sizeof(*rp)) {
405 if ((entry = malloc(sizeof(struct ng_nat_rdr_lst),
406 M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) {
411 /* Try actual redirect. */
412 entry->lnk = LibAliasRedirectPort(priv->lib,
413 rp->local_addr, htons(rp->local_port),
414 rp->remote_addr, htons(rp->remote_port),
415 rp->alias_addr, htons(rp->alias_port),
418 if (entry->lnk == NULL) {
420 free(entry, M_NETGRAPH);
424 /* Successful, save info in our internal list. */
425 entry->rdr.local_addr = rp->local_addr;
426 entry->rdr.alias_addr = rp->alias_addr;
427 entry->rdr.remote_addr = rp->remote_addr;
428 entry->rdr.local_port = rp->local_port;
429 entry->rdr.alias_port = rp->alias_port;
430 entry->rdr.remote_port = rp->remote_port;
431 entry->rdr.proto = rp->proto;
432 bcopy(rp->description, entry->rdr.description,
435 /* Safety precaution. */
436 entry->rdr.description[NG_NAT_DESC_LENGTH-1] = '\0';
438 entry->rdr.id = priv->nextid++;
441 /* Link to list of redirects. */
442 STAILQ_INSERT_TAIL(&priv->redirhead, entry, entries);
444 /* Response with id of newly added entry. */
445 NG_MKRESPONSE(resp, msg, sizeof(entry->rdr.id), M_NOWAIT);
450 bcopy(&entry->rdr.id, resp->data, sizeof(entry->rdr.id));
453 case NGM_NAT_REDIRECT_ADDR:
455 struct ng_nat_rdr_lst *entry;
456 struct ng_nat_redirect_addr *const ra =
457 (struct ng_nat_redirect_addr *)msg->data;
459 if (msg->header.arglen < sizeof(*ra)) {
464 if ((entry = malloc(sizeof(struct ng_nat_rdr_lst),
465 M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) {
470 /* Try actual redirect. */
471 entry->lnk = LibAliasRedirectAddr(priv->lib,
472 ra->local_addr, ra->alias_addr);
474 if (entry->lnk == NULL) {
476 free(entry, M_NETGRAPH);
480 /* Successful, save info in our internal list. */
481 entry->rdr.local_addr = ra->local_addr;
482 entry->rdr.alias_addr = ra->alias_addr;
483 entry->rdr.proto = NG_NAT_REDIRPROTO_ADDR;
484 bcopy(ra->description, entry->rdr.description,
487 /* Safety precaution. */
488 entry->rdr.description[NG_NAT_DESC_LENGTH-1] = '\0';
490 entry->rdr.id = priv->nextid++;
493 /* Link to list of redirects. */
494 STAILQ_INSERT_TAIL(&priv->redirhead, entry, entries);
496 /* Response with id of newly added entry. */
497 NG_MKRESPONSE(resp, msg, sizeof(entry->rdr.id), M_NOWAIT);
502 bcopy(&entry->rdr.id, resp->data, sizeof(entry->rdr.id));
505 case NGM_NAT_REDIRECT_PROTO:
507 struct ng_nat_rdr_lst *entry;
508 struct ng_nat_redirect_proto *const rp =
509 (struct ng_nat_redirect_proto *)msg->data;
511 if (msg->header.arglen < sizeof(*rp)) {
516 if ((entry = malloc(sizeof(struct ng_nat_rdr_lst),
517 M_NETGRAPH, M_NOWAIT | M_ZERO)) == NULL) {
522 /* Try actual redirect. */
523 entry->lnk = LibAliasRedirectProto(priv->lib,
524 rp->local_addr, rp->remote_addr,
525 rp->alias_addr, rp->proto);
527 if (entry->lnk == NULL) {
529 free(entry, M_NETGRAPH);
533 /* Successful, save info in our internal list. */
534 entry->rdr.local_addr = rp->local_addr;
535 entry->rdr.alias_addr = rp->alias_addr;
536 entry->rdr.remote_addr = rp->remote_addr;
537 entry->rdr.proto = rp->proto;
538 bcopy(rp->description, entry->rdr.description,
541 /* Safety precaution. */
542 entry->rdr.description[NG_NAT_DESC_LENGTH-1] = '\0';
544 entry->rdr.id = priv->nextid++;
547 /* Link to list of redirects. */
548 STAILQ_INSERT_TAIL(&priv->redirhead, entry, entries);
550 /* Response with id of newly added entry. */
551 NG_MKRESPONSE(resp, msg, sizeof(entry->rdr.id), M_NOWAIT);
556 bcopy(&entry->rdr.id, resp->data, sizeof(entry->rdr.id));
559 case NGM_NAT_REDIRECT_DYNAMIC:
560 case NGM_NAT_REDIRECT_DELETE:
562 struct ng_nat_rdr_lst *entry;
563 uint32_t *const id = (uint32_t *)msg->data;
565 if (msg->header.arglen < sizeof(*id)) {
570 /* Find entry with supplied id. */
571 STAILQ_FOREACH(entry, &priv->redirhead, entries) {
572 if (entry->rdr.id == *id)
582 if (msg->header.cmd == NGM_NAT_REDIRECT_DYNAMIC) {
583 if (LibAliasRedirectDynamic(priv->lib,
585 error = ENOTTY; /* XXX Something better? */
588 } else { /* NGM_NAT_REDIRECT_DELETE */
589 LibAliasRedirectDelete(priv->lib, entry->lnk);
592 /* Delete entry from our internal list. */
594 STAILQ_REMOVE(&priv->redirhead, entry, ng_nat_rdr_lst, entries);
595 free(entry, M_NETGRAPH);
598 case NGM_NAT_ADD_SERVER:
600 struct ng_nat_rdr_lst *entry;
601 struct ng_nat_add_server *const as =
602 (struct ng_nat_add_server *)msg->data;
604 if (msg->header.arglen < sizeof(*as)) {
609 /* Find entry with supplied id. */
610 STAILQ_FOREACH(entry, &priv->redirhead, entries) {
611 if (entry->rdr.id == as->id)
621 if (LibAliasAddServer(priv->lib, entry->lnk,
622 as->addr, htons(as->port)) == -1) {
630 case NGM_NAT_LIST_REDIRECTS:
632 struct ng_nat_rdr_lst *entry;
633 struct ng_nat_list_redirects *ary;
636 NG_MKRESPONSE(resp, msg, sizeof(*ary) +
637 (priv->rdrcount) * sizeof(*entry), M_NOWAIT);
643 ary = (struct ng_nat_list_redirects *)resp->data;
644 ary->total_count = priv->rdrcount;
646 STAILQ_FOREACH(entry, &priv->redirhead, entries) {
647 bcopy(&entry->rdr, &ary->redirects[i++],
648 sizeof(struct ng_nat_listrdrs_entry));
652 case NGM_NAT_PROXY_RULE:
654 char *cmd = (char *)msg->data;
656 if (msg->header.arglen < 6) {
661 if (LibAliasProxyRule(priv->lib, cmd) != 0)
665 case NGM_NAT_LIBALIAS_INFO:
667 struct ng_nat_libalias_info *i;
669 NG_MKRESPONSE(resp, msg,
670 sizeof(struct ng_nat_libalias_info), M_NOWAIT);
675 i = (struct ng_nat_libalias_info *)resp->data;
676 #define COPY(F) do { \
677 if (priv->lib->F >= 0 && priv->lib->F < UINT32_MAX) \
678 i->F = priv->lib->F; \
688 COPY(protoLinkCount);
689 COPY(fragmentIdLinkCount);
690 COPY(fragmentPtrLinkCount);
696 error = EINVAL; /* unknown command */
701 error = EINVAL; /* unknown cookie type */
705 NG_RESPOND_MSG(error, node, item, resp);
711 ng_nat_rcvdata(hook_p hook, item_p item )
713 const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
719 /* We have no required hooks. */
720 if (!(priv->flags & NGNAT_CONNECTED)) {
725 /* We have no alias address yet to do anything. */
726 if (!(priv->flags & NGNAT_ADDR_DEFINED))
731 if ((m = m_megapullup(m, m->m_pkthdr.len)) == NULL) {
732 NGI_M(item) = NULL; /* avoid double free */
740 ip = mtod(m, struct ip *);
742 KASSERT(m->m_pkthdr.len == ntohs(ip->ip_len),
743 ("ng_nat: ip_len != m_pkthdr.len"));
746 * We drop packet when:
747 * 1. libalias returns PKT_ALIAS_ERROR;
748 * 2. For incoming packets:
749 * a) for unresolved fragments;
750 * b) libalias returns PKT_ALIAS_IGNORED and
751 * PKT_ALIAS_DENY_INCOMING flag is set.
753 if (hook == priv->in) {
754 rval = LibAliasIn(priv->lib, c, m->m_len + M_TRAILINGSPACE(m));
755 if (rval == PKT_ALIAS_ERROR ||
756 rval == PKT_ALIAS_UNRESOLVED_FRAGMENT ||
757 (rval == PKT_ALIAS_IGNORED &&
758 (priv->lib->packetAliasMode &
759 PKT_ALIAS_DENY_INCOMING) != 0)) {
763 } else if (hook == priv->out) {
764 rval = LibAliasOut(priv->lib, c, m->m_len + M_TRAILINGSPACE(m));
765 if (rval == PKT_ALIAS_ERROR) {
770 panic("ng_nat: unknown hook!\n");
772 if (rval == PKT_ALIAS_RESPOND)
773 m->m_flags |= M_SKIP_FIREWALL;
774 m->m_pkthdr.len = m->m_len = ntohs(ip->ip_len);
776 if ((ip->ip_off & htons(IP_OFFMASK)) == 0 &&
777 ip->ip_p == IPPROTO_TCP) {
778 struct tcphdr *th = (struct tcphdr *)((caddr_t)ip +
782 * Here is our terrible HACK.
784 * Sometimes LibAlias edits contents of TCP packet.
785 * In this case it needs to recompute full TCP
786 * checksum. However, the problem is that LibAlias
787 * doesn't have any idea about checksum offloading
788 * in kernel. To workaround this, we do not do
789 * checksumming in LibAlias, but only mark the
790 * packets in th_x2 field. If we receive a marked
791 * packet, we calculate correct checksum for it
792 * aware of offloading.
794 * Why do I do such a terrible hack instead of
795 * recalculating checksum for each packet?
796 * Because the previous checksum was not checked!
797 * Recalculating checksums for EVERY packet will
798 * hide ALL transmission errors. Yes, marked packets
799 * still suffer from this problem. But, sigh, natd(8)
800 * has this problem, too.
804 uint16_t ip_len = ntohs(ip->ip_len);
807 th->th_sum = in_pseudo(ip->ip_src.s_addr,
808 ip->ip_dst.s_addr, htons(IPPROTO_TCP +
809 ip_len - (ip->ip_hl << 2)));
811 if ((m->m_pkthdr.csum_flags & CSUM_TCP) == 0) {
812 m->m_pkthdr.csum_data = offsetof(struct tcphdr,
820 if (hook == priv->in)
821 NG_FWD_ITEM_HOOK(error, item, priv->out);
823 NG_FWD_ITEM_HOOK(error, item, priv->in);
829 ng_nat_shutdown(node_p node)
831 const priv_p priv = NG_NODE_PRIVATE(node);
833 NG_NODE_SET_PRIVATE(node, NULL);
836 /* Free redirects list. */
837 while (!STAILQ_EMPTY(&priv->redirhead)) {
838 struct ng_nat_rdr_lst *entry = STAILQ_FIRST(&priv->redirhead);
839 STAILQ_REMOVE_HEAD(&priv->redirhead, entries);
840 free(entry, M_NETGRAPH);
844 LibAliasUninit(priv->lib);
845 free(priv, M_NETGRAPH);
851 ng_nat_disconnect(hook_p hook)
853 const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
855 priv->flags &= ~NGNAT_CONNECTED;
857 if (hook == priv->out)
859 if (hook == priv->in)
862 if (priv->out == NULL && priv->in == NULL)
863 ng_rmnode_self(NG_HOOK_NODE(hook));
869 ng_nat_translate_flags(unsigned int x)
871 unsigned int res = 0;
874 res |= PKT_ALIAS_LOG;
875 if (x & NG_NAT_DENY_INCOMING)
876 res |= PKT_ALIAS_DENY_INCOMING;
877 if (x & NG_NAT_SAME_PORTS)
878 res |= PKT_ALIAS_SAME_PORTS;
879 if (x & NG_NAT_UNREGISTERED_ONLY)
880 res |= PKT_ALIAS_UNREGISTERED_ONLY;
881 if (x & NG_NAT_RESET_ON_ADDR_CHANGE)
882 res |= PKT_ALIAS_RESET_ON_ADDR_CHANGE;
883 if (x & NG_NAT_PROXY_ONLY)
884 res |= PKT_ALIAS_PROXY_ONLY;
885 if (x & NG_NAT_REVERSE)
886 res |= PKT_ALIAS_REVERSE;