19 #include <linux/module.h>
20 #include <linux/kernel.h>
23 #include <linux/types.h>
27 #include <linux/errno.h>
28 #include <linux/netlink.h>
31 #include <linux/slab.h>
33 #include <linux/netfilter.h>
46 #ifdef CONFIG_NF_NAT_NEEDED
52 #include <linux/netfilter/nfnetlink.h>
60 ctnetlink_dump_tuples_proto(
struct sk_buff *
skb,
76 nla_nest_end(skb, nest_parms);
85 ctnetlink_dump_tuples_ip(
struct sk_buff *skb,
99 nla_nest_end(skb, nest_parms);
108 ctnetlink_dump_tuples(
struct sk_buff *skb,
116 l3proto = __nf_ct_l3proto_find(tuple->
src.l3num);
117 ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
121 tuple->
dst.protonum);
122 ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto);
132 goto nla_put_failure;
140 ctnetlink_dump_timeout(
struct sk_buff *skb,
const struct nf_conn *ct)
148 goto nla_put_failure;
159 struct nlattr *nest_proto;
168 goto nla_put_failure;
170 ret = l4proto->
to_nlattr(skb, nest_proto, ct);
172 nla_nest_end(skb, nest_proto);
181 ctnetlink_dump_helpinfo(
struct sk_buff *skb,
const struct nf_conn *ct)
183 struct nlattr *nest_helper;
196 goto nla_put_failure;
198 goto nla_put_failure;
203 nla_nest_end(skb, nest_helper);
216 struct nlattr *nest_count;
220 goto nla_put_failure;
224 goto nla_put_failure;
226 nla_nest_end(skb, nest_count);
235 ctnetlink_dump_counters(
struct sk_buff *skb,
const struct nf_conn *ct,
241 acct = nf_conn_acct_find(ct);
256 ctnetlink_dump_timestamp(
struct sk_buff *skb,
const struct nf_conn *ct)
258 struct nlattr *nest_count;
261 tstamp = nf_conn_tstamp_find(ct);
267 goto nla_put_failure;
272 goto nla_put_failure;
273 nla_nest_end(skb, nest_count);
281 #ifdef CONFIG_NF_CONNTRACK_MARK
286 goto nla_put_failure;
293 #define ctnetlink_dump_mark(a, b) (0)
296 #ifdef CONFIG_NF_CONNTRACK_SECMARK
300 struct nlattr *nest_secctx;
311 goto nla_put_failure;
314 goto nla_put_failure;
315 nla_nest_end(skb, nest_secctx);
323 #define ctnetlink_dump_secctx(a, b) (0)
326 #define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
329 ctnetlink_dump_master(
struct sk_buff *skb,
const struct nf_conn *ct)
331 struct nlattr *nest_parms;
338 goto nla_put_failure;
340 goto nla_put_failure;
341 nla_nest_end(skb, nest_parms);
349 #ifdef CONFIG_NF_NAT_NEEDED
353 struct nlattr *nest_parms;
357 goto nla_put_failure;
365 goto nla_put_failure;
367 nla_nest_end(skb, nest_parms);
395 #define ctnetlink_dump_nat_seq_adj(a, b) (0)
401 if (nla_put_be32(skb,
CTA_ID,
htonl((
unsigned long)ct)))
402 goto nla_put_failure;
413 goto nla_put_failure;
426 struct nlattr *nest_parms;
430 nlh = nlmsg_put(skb, portid, seq,
event,
sizeof(*nfmsg), flags);
434 nfmsg = nlmsg_data(nlh);
441 goto nla_put_failure;
443 goto nla_put_failure;
444 nla_nest_end(skb, nest_parms);
448 goto nla_put_failure;
450 goto nla_put_failure;
451 nla_nest_end(skb, nest_parms);
453 if (nf_ct_zone(ct) &&
455 goto nla_put_failure;
457 if (ctnetlink_dump_status(skb, ct) < 0 ||
458 ctnetlink_dump_timeout(skb, ct) < 0 ||
461 ctnetlink_dump_timestamp(skb, ct) < 0 ||
462 ctnetlink_dump_protoinfo(skb, ct) < 0 ||
463 ctnetlink_dump_helpinfo(skb, ct) < 0 ||
466 ctnetlink_dump_id(skb, ct) < 0 ||
467 ctnetlink_dump_use(skb, ct) < 0 ||
468 ctnetlink_dump_master(skb, ct) < 0 ||
470 goto nla_put_failure;
477 nlmsg_cancel(skb, nlh);
482 ctnetlink_proto_size(
const struct nf_conn *ct)
489 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
500 ctnetlink_counters_size(
const struct nf_conn *ct)
504 return 2 * nla_total_size(0)
505 + 2 * nla_total_size(
sizeof(
uint64_t))
506 + 2 * nla_total_size(
sizeof(
uint64_t))
511 ctnetlink_secctx_size(
const struct nf_conn *ct)
513 #ifdef CONFIG_NF_CONNTRACK_SECMARK
520 return nla_total_size(0)
521 + nla_total_size(
sizeof(
char) * len);
528 ctnetlink_timestamp_size(
const struct nf_conn *ct)
530 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
531 if (!nf_ct_ext_exist(ct, NF_CT_EXT_TSTAMP))
533 return nla_total_size(0) + 2 * nla_total_size(
sizeof(
uint64_t));
540 ctnetlink_nlmsg_size(
const struct nf_conn *ct)
543 + 3 * nla_total_size(0)
544 + 3 * nla_total_size(0)
545 + 3 * nla_total_size(0)
546 + 3 * nla_total_size(
sizeof(
u_int8_t))
549 + ctnetlink_counters_size(ct)
550 + ctnetlink_timestamp_size(ct)
555 + ctnetlink_secctx_size(ct)
556 #ifdef CONFIG_NF_NAT_NEEDED
557 + 2 * nla_total_size(0)
560 #ifdef CONFIG_NF_CONNTRACK_MARK
563 + ctnetlink_proto_size(ct)
567 #ifdef CONFIG_NF_CONNTRACK_EVENTS
569 ctnetlink_conntrack_event(
unsigned int events,
struct nf_ct_event *
item)
574 struct nlattr *nest_parms;
578 unsigned int flags = 0,
group;
582 if (nf_ct_is_untracked(ct))
602 skb = nlmsg_new(ctnetlink_nlmsg_size(ct),
GFP_ATOMIC);
607 nlh = nlmsg_put(skb, item->portid, 0, type,
sizeof(*nfmsg), flags);
611 nfmsg = nlmsg_data(nlh);
619 goto nla_put_failure;
621 goto nla_put_failure;
622 nla_nest_end(skb, nest_parms);
626 goto nla_put_failure;
628 goto nla_put_failure;
629 nla_nest_end(skb, nest_parms);
631 if (nf_ct_zone(ct) &&
633 goto nla_put_failure;
635 if (ctnetlink_dump_id(skb, ct) < 0)
636 goto nla_put_failure;
638 if (ctnetlink_dump_status(skb, ct) < 0)
639 goto nla_put_failure;
642 if (ctnetlink_dump_counters(skb, ct,
644 ctnetlink_dump_counters(skb, ct,
646 ctnetlink_dump_timestamp(skb, ct) < 0)
647 goto nla_put_failure;
649 if (ctnetlink_dump_timeout(skb, ct) < 0)
650 goto nla_put_failure;
653 && ctnetlink_dump_protoinfo(skb, ct) < 0)
654 goto nla_put_failure;
657 && ctnetlink_dump_helpinfo(skb, ct) < 0)
658 goto nla_put_failure;
660 #ifdef CONFIG_NF_CONNTRACK_SECMARK
663 goto nla_put_failure;
667 ctnetlink_dump_master(skb, ct) < 0)
668 goto nla_put_failure;
672 goto nla_put_failure;
675 #ifdef CONFIG_NF_CONNTRACK_MARK
676 if ((events & (1 <<
IPCT_MARK) || ct->mark)
678 goto nla_put_failure;
692 nlmsg_cancel(skb, nlh);
722 struct net *net = sock_net(skb->
sk);
729 #ifdef CONFIG_NF_CONNTRACK_MARK
735 for (; cb->
args[0] < net->ct.htable_size; cb->
args[0]++) {
741 ct = nf_ct_tuplehash_to_ctrack(h);
745 if (l3proto && nf_ct_l3num(ct) != l3proto)
752 #ifdef CONFIG_NF_CONNTRACK_MARK
753 if (filter && !((ct->mark & filter->
mark.mask) ==
777 spin_unlock_bh(&nf_conntrack_lock);
794 l3proto = __nf_ct_l3proto_find(tuple->
src.l3num);
813 ctnetlink_parse_tuple_proto(
struct nlattr *attr,
820 ret = nla_parse_nested(tb,
CTA_PROTO_MAX, attr, proto_nla_policy);
826 tuple->
dst.protonum = nla_get_u8(tb[CTA_PROTO_NUM]);
849 ctnetlink_parse_tuple(
const struct nlattr *
const cda[],
856 memset(tuple, 0,
sizeof(*tuple));
858 nla_parse_nested(tb,
CTA_TUPLE_MAX, cda[type], tuple_nla_policy);
863 tuple->
src.l3num = l3num;
865 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP], tuple);
872 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO], tuple);
889 #ifdef CONFIG_NF_CONNTRACK_ZONES
890 *zone =
ntohs(nla_get_be16(attr));
905 ctnetlink_parse_help(
const struct nlattr *attr,
char **helper_name,
910 nla_parse_nested(tb,
CTA_HELP_MAX, attr, help_nla_policy);
915 *helper_name = nla_data(tb[CTA_HELP_NAME]);
940 ctnetlink_del_conntrack(
struct sock *ctnl,
struct sk_buff *skb,
942 const struct nlattr *
const cda[])
944 struct net *net = sock_net(ctnl);
948 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
953 err = ctnetlink_parse_zone(cda[
CTA_ZONE], &zone);
958 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
960 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
976 ct = nf_ct_tuplehash_to_ctrack(h);
980 if (
id != (
u32)(
unsigned long)ct) {
989 nlmsg_report(nlh)) < 0) {
1007 ctnetlink_get_conntrack(
struct sock *ctnl,
struct sk_buff *skb,
1009 const struct nlattr *
const cda[])
1011 struct net *net = sock_net(ctnl);
1016 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1023 .dump = ctnetlink_dump_table,
1024 .done = ctnetlink_done,
1026 #ifdef CONFIG_NF_CONNTRACK_MARK
1037 ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
1041 return netlink_dump_start(ctnl, skb, nlh, &c);
1044 err = ctnetlink_parse_zone(cda[
CTA_ZONE], &zone);
1048 if (cda[CTA_TUPLE_ORIG])
1049 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
1050 else if (cda[CTA_TUPLE_REPLY])
1051 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
1062 ct = nf_ct_tuplehash_to_ctrack(h);
1092 #ifdef CONFIG_NF_NAT_NEEDED
1094 ctnetlink_parse_nat_setup(
struct nf_conn *ct,
1096 const struct nlattr *attr)
1102 if (!parse_nat_setup) {
1103 #ifdef CONFIG_MODULES
1106 if (request_module(
"nf-nat") < 0) {
1113 if (nfnetlink_parse_nat_setup_hook)
1119 err = parse_nat_setup(ct, manip, attr);
1121 #ifdef CONFIG_MODULES
1124 if (request_module(
"nf-nat-%u", nf_ct_l3num(ct)) < 0) {
1140 ctnetlink_change_status(
struct nf_conn *ct,
const struct nlattr *
const cda[])
1166 ctnetlink_change_nat(
struct nf_conn *ct,
const struct nlattr *
const cda[])
1168 #ifdef CONFIG_NF_NAT_NEEDED
1172 ret = ctnetlink_parse_nat_setup(ct,
1179 ret = ctnetlink_parse_nat_setup(ct,
1192 ctnetlink_change_helper(
struct nf_conn *ct,
const struct nlattr *
const cda[])
1196 char *helpname =
NULL;
1204 err = ctnetlink_parse_help(cda[
CTA_HELP], &helpname, &helpinfo);
1208 if (!
strcmp(helpname,
"")) {
1209 if (help && help->
helper) {
1219 nf_ct_protonum(ct));
1220 if (helper ==
NULL) {
1221 #ifdef CONFIG_MODULES
1222 spin_unlock_bh(&nf_conntrack_lock);
1224 if (request_module(
"nfct-helper-%s", helpname) < 0) {
1225 spin_lock_bh(&nf_conntrack_lock);
1229 spin_lock_bh(&nf_conntrack_lock);
1231 nf_ct_protonum(ct));
1239 if (help->
helper == helper) {
1253 ctnetlink_change_timeout(
struct nf_conn *ct,
const struct nlattr *
const cda[])
1273 ctnetlink_change_protoinfo(
struct nf_conn *ct,
const struct nlattr *
const cda[])
1291 #ifdef CONFIG_NF_NAT_NEEDED
1299 change_nat_seq_adj(
struct nf_nat_seq *natseq,
const struct nlattr *
const attr)
1309 ntohl(nla_get_be32(cda[CTA_NAT_SEQ_CORRECTION_POS]));
1315 ntohl(nla_get_be32(cda[CTA_NAT_SEQ_OFFSET_BEFORE]));
1321 ntohl(nla_get_be32(cda[CTA_NAT_SEQ_OFFSET_AFTER]));
1327 ctnetlink_change_nat_seq_adj(
struct nf_conn *ct,
1328 const struct nlattr *
const cda[])
1338 cda[CTA_NAT_SEQ_ADJ_ORIG]);
1347 cda[CTA_NAT_SEQ_ADJ_REPLY]);
1359 ctnetlink_change_conntrack(
struct nf_conn *ct,
1360 const struct nlattr *
const cda[])
1369 err = ctnetlink_change_helper(ct, cda);
1375 err = ctnetlink_change_timeout(ct, cda);
1381 err = ctnetlink_change_status(ct, cda);
1387 err = ctnetlink_change_protoinfo(ct, cda);
1392 #if defined(CONFIG_NF_CONNTRACK_MARK)
1394 ct->mark =
ntohl(nla_get_be32(cda[CTA_MARK]));
1397 #ifdef CONFIG_NF_NAT_NEEDED
1398 if (cda[CTA_NAT_SEQ_ADJ_ORIG] || cda[CTA_NAT_SEQ_ADJ_REPLY]) {
1399 err = ctnetlink_change_nat_seq_adj(ct, cda);
1409 ctnetlink_create_conntrack(
struct net *net,
u16 zone,
1410 const struct nlattr *
const cda[],
1424 if (!cda[CTA_TIMEOUT])
1426 ct->
timeout.expires =
ntohl(nla_get_be32(cda[CTA_TIMEOUT]));
1431 if (cda[CTA_HELP]) {
1432 char *helpname =
NULL;
1435 err = ctnetlink_parse_help(cda[CTA_HELP], &helpname, &helpinfo);
1440 nf_ct_protonum(ct));
1441 if (helper ==
NULL) {
1443 #ifdef CONFIG_MODULES
1444 if (request_module(
"nfct-helper-%s", helpname) < 0) {
1452 nf_ct_protonum(ct));
1483 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {
1484 err = ctnetlink_change_nat(ct, cda);
1495 if (cda[CTA_STATUS]) {
1496 err = ctnetlink_change_status(ct, cda);
1501 #ifdef CONFIG_NF_NAT_NEEDED
1502 if (cda[CTA_NAT_SEQ_ADJ_ORIG] || cda[CTA_NAT_SEQ_ADJ_REPLY]) {
1503 err = ctnetlink_change_nat_seq_adj(ct, cda);
1510 if (cda[CTA_PROTOINFO]) {
1511 err = ctnetlink_change_protoinfo(ct, cda);
1516 #if defined(CONFIG_NF_CONNTRACK_MARK)
1518 ct->mark =
ntohl(nla_get_be32(cda[CTA_MARK]));
1522 if (cda[CTA_TUPLE_MASTER]) {
1527 err = ctnetlink_parse_tuple(cda, &
master, CTA_TUPLE_MASTER, u3);
1532 if (master_h ==
NULL) {
1536 master_ct = nf_ct_tuplehash_to_ctrack(master_h);
1540 tstamp = nf_conn_tstamp_find(ct);
1556 return ERR_PTR(err);
1560 ctnetlink_new_conntrack(
struct sock *ctnl,
struct sk_buff *skb,
1562 const struct nlattr *
const cda[])
1564 struct net *net = sock_net(ctnl);
1567 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1573 err = ctnetlink_parse_zone(cda[
CTA_ZONE], &zone);
1577 if (cda[CTA_TUPLE_ORIG]) {
1578 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
1583 if (cda[CTA_TUPLE_REPLY]) {
1584 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
1589 if (cda[CTA_TUPLE_ORIG])
1591 else if (cda[CTA_TUPLE_REPLY])
1599 ct = ctnetlink_create_conntrack(net, zone, cda, &otuple,
1610 nf_conntrack_eventmask_report((1 <<
IPCT_REPLY) |
1626 ct = nf_ct_tuplehash_to_ctrack(h);
1628 spin_lock_bh(&nf_conntrack_lock);
1629 err = ctnetlink_change_conntrack(ct, cda);
1630 spin_unlock_bh(&nf_conntrack_lock);
1632 nf_conntrack_eventmask_report((1 <<
IPCT_REPLY) |
1648 ctnetlink_ct_stat_cpu_fill_info(
struct sk_buff *skb,
u32 portid,
u32 seq,
1656 nlh = nlmsg_put(skb, portid, seq,
event,
sizeof(*nfmsg), flags);
1660 nfmsg = nlmsg_data(nlh);
1680 goto nla_put_failure;
1682 nlmsg_end(skb, nlh);
1687 nlmsg_cancel(skb, nlh);
1695 struct net *net = sock_net(skb->
sk);
1697 if (cb->
args[0] == nr_cpu_ids)
1700 for (cpu = cb->
args[0]; cpu < nr_cpu_ids; cpu++) {
1707 if (ctnetlink_ct_stat_cpu_fill_info(skb,
1719 ctnetlink_stat_ct_cpu(
struct sock *ctnl,
struct sk_buff *skb,
1721 const struct nlattr *
const cda[])
1725 .
dump = ctnetlink_ct_stat_cpu_dump,
1727 return netlink_dump_start(ctnl, skb, nlh, &c);
1734 ctnetlink_stat_ct_fill_info(
struct sk_buff *skb,
u32 portid,
u32 seq,
u32 type,
1743 nlh = nlmsg_put(skb, portid, seq,
event,
sizeof(*nfmsg), flags);
1747 nfmsg = nlmsg_data(nlh);
1753 goto nla_put_failure;
1755 nlmsg_end(skb, nlh);
1760 nlmsg_cancel(skb, nlh);
1765 ctnetlink_stat_ct(
struct sock *ctnl,
struct sk_buff *skb,
1767 const struct nlattr *
const cda[])
1776 err = ctnetlink_stat_ct_fill_info(skb2,
NETLINK_CB(skb).portid,
1796 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT
1798 ctnetlink_nfqueue_build_size(
const struct nf_conn *ct)
1800 return 3 * nla_total_size(0)
1801 + 3 * nla_total_size(0)
1802 + 3 * nla_total_size(0)
1803 + 3 * nla_total_size(
sizeof(
u_int8_t))
1810 + ctnetlink_secctx_size(ct)
1811 #ifdef CONFIG_NF_NAT_NEEDED
1812 + 2 * nla_total_size(0)
1815 #ifdef CONFIG_NF_CONNTRACK_MARK
1818 + ctnetlink_proto_size(ct)
1825 struct nlattr *nest_parms;
1828 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG |
NLA_F_NESTED);
1830 goto nla_put_failure;
1832 goto nla_put_failure;
1833 nla_nest_end(skb, nest_parms);
1835 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY |
NLA_F_NESTED);
1837 goto nla_put_failure;
1839 goto nla_put_failure;
1840 nla_nest_end(skb, nest_parms);
1842 if (nf_ct_zone(ct)) {
1844 goto nla_put_failure;
1847 if (ctnetlink_dump_id(skb, ct) < 0)
1848 goto nla_put_failure;
1850 if (ctnetlink_dump_status(skb, ct) < 0)
1851 goto nla_put_failure;
1853 if (ctnetlink_dump_timeout(skb, ct) < 0)
1854 goto nla_put_failure;
1856 if (ctnetlink_dump_protoinfo(skb, ct) < 0)
1857 goto nla_put_failure;
1859 if (ctnetlink_dump_helpinfo(skb, ct) < 0)
1860 goto nla_put_failure;
1862 #ifdef CONFIG_NF_CONNTRACK_SECMARK
1864 goto nla_put_failure;
1866 if (ct->
master && ctnetlink_dump_master(skb, ct) < 0)
1867 goto nla_put_failure;
1871 goto nla_put_failure;
1873 #ifdef CONFIG_NF_CONNTRACK_MARK
1875 goto nla_put_failure;
1886 ctnetlink_nfqueue_parse_ct(
const struct nlattr *cda[],
struct nf_conn *ct)
1890 if (cda[CTA_TIMEOUT]) {
1891 err = ctnetlink_change_timeout(ct, cda);
1895 if (cda[CTA_STATUS]) {
1896 err = ctnetlink_change_status(ct, cda);
1900 if (cda[CTA_HELP]) {
1901 err = ctnetlink_change_helper(ct, cda);
1905 #if defined(CONFIG_NF_CONNTRACK_MARK)
1907 ct->mark =
ntohl(nla_get_be32(cda[CTA_MARK]));
1913 ctnetlink_nfqueue_parse(
const struct nlattr *attr,
struct nf_conn *ct)
1918 nla_parse_nested(cda,
CTA_MAX, attr, ct_nla_policy);
1920 spin_lock_bh(&nf_conntrack_lock);
1921 ret = ctnetlink_nfqueue_parse_ct((
const struct nlattr **)cda, ct);
1922 spin_unlock_bh(&nf_conntrack_lock);
1927 static struct nfq_ct_hook ctnetlink_nfqueue_hook = {
1928 .build_size = ctnetlink_nfqueue_build_size,
1929 .build = ctnetlink_nfqueue_build,
1930 .parse = ctnetlink_nfqueue_parse,
1939 ctnetlink_exp_dump_tuple(
struct sk_buff *skb,
1943 struct nlattr *nest_parms;
1947 goto nla_put_failure;
1948 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1949 goto nla_put_failure;
1950 nla_nest_end(skb, nest_parms);
1959 ctnetlink_exp_dump_mask(
struct sk_buff *skb,
1967 struct nlattr *nest_parms;
1970 memcpy(&
m.src.u3, &mask->
src.u3,
sizeof(
m.src.u3));
1971 m.src.u.all = mask->
src.u.all;
1972 m.dst.protonum = tuple->
dst.protonum;
1976 goto nla_put_failure;
1979 l3proto = __nf_ct_l3proto_find(tuple->
src.l3num);
1980 ret = ctnetlink_dump_tuples_ip(skb, &
m, l3proto);
1983 tuple->
dst.protonum);
1984 ret = ctnetlink_dump_tuples_proto(skb, &
m, l4proto);
1989 goto nla_put_failure;
1991 nla_nest_end(skb, nest_parms);
2002 ctnetlink_exp_dump_expect(
struct sk_buff *skb,
2008 #ifdef CONFIG_NF_NAT_NEEDED
2009 struct nlattr *nest_parms;
2018 goto nla_put_failure;
2019 if (ctnetlink_exp_dump_mask(skb, &exp->
tuple, &exp->
mask) < 0)
2020 goto nla_put_failure;
2021 if (ctnetlink_exp_dump_tuple(skb,
2024 goto nla_put_failure;
2026 #ifdef CONFIG_NF_NAT_NEEDED
2027 if (!nf_inet_addr_cmp(&exp->saved_addr, &any_addr) ||
2028 exp->saved_proto.all) {
2031 goto nla_put_failure;
2034 goto nla_put_failure;
2036 nat_tuple.
src.l3num = nf_ct_l3num(master);
2037 nat_tuple.
src.u3 = exp->saved_addr;
2038 nat_tuple.
dst.protonum = nf_ct_protonum(master);
2039 nat_tuple.
src.u = exp->saved_proto;
2041 if (ctnetlink_exp_dump_tuple(skb, &nat_tuple,
2043 goto nla_put_failure;
2044 nla_nest_end(skb, nest_parms);
2051 goto nla_put_failure;
2052 help = nfct_help(master);
2059 goto nla_put_failure;
2062 if (expfn !=
NULL &&
2064 goto nla_put_failure;
2073 ctnetlink_exp_fill_info(
struct sk_buff *skb,
u32 portid,
u32 seq,
2081 nlh = nlmsg_put(skb, portid, seq, event,
sizeof(*nfmsg), flags);
2085 nfmsg = nlmsg_data(nlh);
2090 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
2091 goto nla_put_failure;
2093 nlmsg_end(skb, nlh);
2098 nlmsg_cancel(skb, nlh);
2102 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2104 ctnetlink_expect_event(
unsigned int events,
struct nf_exp_event *item)
2107 struct net *net = nf_ct_exp_net(exp);
2132 nlh = nlmsg_put(skb, item->portid, 0, type,
sizeof(*nfmsg), flags);
2136 nfmsg = nlmsg_data(nlh);
2142 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
2143 goto nla_put_failure;
2146 nlmsg_end(skb, nlh);
2152 nlmsg_cancel(skb, nlh);
2170 struct net *net = sock_net(skb->
sk);
2182 if (l3proto && exp->
tuple.src.l3num != l3proto)
2189 if (ctnetlink_exp_fill_info(skb,
2228 ctnetlink_get_expect(
struct sock *ctnl,
struct sk_buff *skb,
2230 const struct nlattr *
const cda[])
2232 struct net *net = sock_net(ctnl);
2236 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2243 .
dump = ctnetlink_exp_dump_table,
2244 .done = ctnetlink_exp_done,
2246 return netlink_dump_start(ctnl, skb, nlh, &c);
2254 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2256 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
2268 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
2269 if (
ntohl(
id) != (
u32)(
unsigned long)exp) {
2283 err = ctnetlink_exp_fill_info(skb2,
NETLINK_CB(skb).portid,
2304 ctnetlink_del_expect(
struct sock *ctnl,
struct sk_buff *skb,
2306 const struct nlattr *
const cda[])
2308 struct net *net = sock_net(ctnl);
2311 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2318 if (cda[CTA_EXPECT_TUPLE]) {
2324 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2333 if (cda[CTA_EXPECT_ID]) {
2334 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
2335 if (
ntohl(
id) != (
u32)(
unsigned long)exp) {
2342 spin_lock_bh(&nf_conntrack_lock);
2348 spin_unlock_bh(&nf_conntrack_lock);
2353 char *
name = nla_data(cda[CTA_EXPECT_HELP_NAME]);
2357 spin_lock_bh(&nf_conntrack_lock);
2360 &net->ct.expect_hash[i],
2362 m_help = nfct_help(exp->
master);
2372 spin_unlock_bh(&nf_conntrack_lock);
2375 spin_lock_bh(&nf_conntrack_lock);
2376 for (i = 0; i < nf_ct_expect_hsize; i++) {
2378 &net->ct.expect_hash[i],
2388 spin_unlock_bh(&nf_conntrack_lock);
2395 const struct nlattr *
const cda[])
2402 ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) *
HZ;
2414 ctnetlink_parse_expect_nat(
const struct nlattr *attr,
2418 #ifdef CONFIG_NF_NAT_NEEDED
2428 err = ctnetlink_parse_tuple((
const struct nlattr *
const *)tb,
2429 &nat_tuple, CTA_EXPECT_NAT_TUPLE, u3);
2433 exp->saved_addr = nat_tuple.
src.u3;
2434 exp->saved_proto = nat_tuple.
src.u;
2444 ctnetlink_create_expect(
struct net *net,
u16 zone,
2445 const struct nlattr *
const cda[],
2459 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2465 err = ctnetlink_parse_tuple(cda, &
master_tuple, CTA_EXPECT_MASTER, u3);
2473 ct = nf_ct_tuplehash_to_ctrack(h);
2476 if (cda[CTA_EXPECT_HELP_NAME]) {
2477 const char *helpname = nla_data(cda[CTA_EXPECT_HELP_NAME]);
2480 nf_ct_protonum(ct));
2481 if (helper ==
NULL) {
2482 #ifdef CONFIG_MODULES
2483 if (request_module(
"nfct-helper-%s", helpname) < 0) {
2490 nf_ct_protonum(ct));
2513 help = nfct_help(ct);
2515 if (!cda[CTA_EXPECT_TIMEOUT]) {
2525 ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
2528 if (cda[CTA_EXPECT_FLAGS]) {
2529 exp->
flags =
ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
2535 const char *name = nla_data(cda[CTA_EXPECT_FN]);
2539 if (expfn ==
NULL) {
2552 exp->
mask.src.u.all = mask.
src.u.all;
2555 err = ctnetlink_parse_expect_nat(cda[CTA_EXPECT_NAT],
2564 nf_ct_put(nf_ct_tuplehash_to_ctrack(h));
2569 ctnetlink_new_expect(
struct sock *ctnl,
struct sk_buff *skb,
2571 const struct nlattr *
const cda[])
2573 struct net *net = sock_net(ctnl);
2576 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2581 if (!cda[CTA_EXPECT_TUPLE]
2583 || !cda[CTA_EXPECT_MASTER])
2590 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2594 spin_lock_bh(&nf_conntrack_lock);
2598 spin_unlock_bh(&nf_conntrack_lock);
2601 err = ctnetlink_create_expect(net, zone, cda,
2611 err = ctnetlink_change_expect(exp, cda);
2612 spin_unlock_bh(&nf_conntrack_lock);
2618 ctnetlink_exp_stat_fill_info(
struct sk_buff *skb,
u32 portid,
u32 seq,
int cpu,
2626 nlh = nlmsg_put(skb, portid, seq, event,
sizeof(*nfmsg), flags);
2630 nfmsg = nlmsg_data(nlh);
2638 goto nla_put_failure;
2640 nlmsg_end(skb, nlh);
2645 nlmsg_cancel(skb, nlh);
2653 struct net *net = sock_net(skb->
sk);
2655 if (cb->
args[0] == nr_cpu_ids)
2658 for (cpu = cb->
args[0]; cpu < nr_cpu_ids; cpu++) {
2665 if (ctnetlink_exp_stat_fill_info(skb,
NETLINK_CB(cb->
skb).portid,
2676 ctnetlink_stat_exp_cpu(
struct sock *ctnl,
struct sk_buff *skb,
2678 const struct nlattr *
const cda[])
2682 .
dump = ctnetlink_exp_stat_cpu_dump,
2684 return netlink_dump_start(ctnl, skb, nlh, &c);
2690 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2691 static struct nf_ct_event_notifier ctnl_notifier = {
2692 .fcn = ctnetlink_conntrack_event,
2695 static struct nf_exp_event_notifier ctnl_notifier_exp = {
2696 .fcn = ctnetlink_expect_event,
2703 .policy = ct_nla_policy },
2706 .policy = ct_nla_policy },
2709 .policy = ct_nla_policy },
2712 .policy = ct_nla_policy },
2720 .policy = exp_nla_policy },
2723 .policy = exp_nla_policy },
2726 .policy = exp_nla_policy },
2731 .name =
"conntrack",
2738 .name =
"conntrack_expect",
2748 static int __net_init ctnetlink_net_init(
struct net *net)
2750 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2755 pr_err(
"ctnetlink_init: cannot register notifier.\n");
2761 pr_err(
"ctnetlink_init: cannot expect register notifier.\n");
2762 goto err_unreg_notifier;
2767 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2775 static void ctnetlink_net_exit(
struct net *net)
2777 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2788 ctnetlink_net_exit(net);
2792 .
init = ctnetlink_net_init,
2793 .exit_batch = ctnetlink_net_exit_batch,
2796 static int __init ctnetlink_init(
void)
2800 pr_info(
"ctnetlink v%s: registering with nfnetlink.\n",
version);
2803 pr_err(
"ctnetlink_init: cannot register with nfnetlink.\n");
2809 pr_err(
"ctnetlink_init: cannot register exp with nfnetlink.\n");
2810 goto err_unreg_subsys;
2815 pr_err(
"ctnetlink_init: cannot register pernet operations\n");
2816 goto err_unreg_exp_subsys;
2818 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT
2824 err_unreg_exp_subsys:
2832 static void __exit ctnetlink_exit(
void)
2834 pr_info(
"ctnetlink: unregistering from nfnetlink.\n");
2839 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT