11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/sysctl.h>
17 #include <linux/dccp.h>
18 #include <linux/slab.h>
74 #define DCCP_MSL (2 * 60 * HZ)
76 static const char *
const dccp_state_names[] = {
89 #define sNO CT_DCCP_NONE
90 #define sRQ CT_DCCP_REQUEST
91 #define sRS CT_DCCP_RESPOND
92 #define sPO CT_DCCP_PARTOPEN
93 #define sOP CT_DCCP_OPEN
94 #define sCR CT_DCCP_CLOSEREQ
95 #define sCG CT_DCCP_CLOSING
96 #define sTW CT_DCCP_TIMEWAIT
97 #define sIG CT_DCCP_IGNORE
98 #define sIV CT_DCCP_INVALID
400 static bool dccp_pkt_to_tuple(
const struct sk_buff *
skb,
unsigned int dataoff,
405 dh = skb_header_pointer(skb, dataoff,
sizeof(_hdr), &_hdr);
417 inv->
src.u.dccp.port = tuple->
dst.u.dccp.port;
418 inv->
dst.u.dccp.port = tuple->
src.u.dccp.port;
423 unsigned int dataoff,
unsigned int *timeouts)
425 struct net *
net = nf_ct_net(ct);
431 dh = skb_header_pointer(skb, dataoff,
sizeof(_dh), &dh);
437 dn = dccp_pernet(net);
439 msg =
"nf_ct_dccp: not picking up existing connection ";
445 msg =
"nf_ct_dccp: invalid state transition ";
467 dhack = (
void *)dh + __dccp_basic_hdr_len(dh);
472 static unsigned int *dccp_get_timeouts(
struct net *net)
474 return dccp_pernet(net)->dccp_timeout;
477 static int dccp_packet(
struct nf_conn *ct,
const struct sk_buff *skb,
480 unsigned int *timeouts)
482 struct net *net = nf_ct_net(ct);
488 dh = skb_header_pointer(skb, dataoff,
sizeof(_dh), &dh);
490 type = dh->dccph_type;
495 nf_ct_kill_acct(ct, ctinfo, skb);
499 spin_lock_bh(&ct->
lock);
503 new_state = dccp_state_table[
role][
type][old_state];
517 ct->
proto.
dccp.handshake_seq = dccp_hdr_seq(dh);
522 dccp_ack_seq(dh) == ct->
proto.
dccp.handshake_seq)
536 ct->
proto.
dccp.handshake_seq = dccp_hdr_seq(dh);
543 spin_unlock_bh(&ct->
lock);
546 "nf_ct_dccp: invalid packet ignored ");
549 spin_unlock_bh(&ct->
lock);
552 "nf_ct_dccp: invalid state transition ");
559 spin_unlock_bh(&ct->
lock);
561 if (new_state != old_state)
564 nf_ct_refresh_acct(ct, ctinfo, skb, timeouts[new_state]);
569 static int dccp_error(
struct net *net,
struct nf_conn *tmpl,
570 struct sk_buff *skb,
unsigned int dataoff,
575 unsigned int dccp_len = skb->
len - dataoff;
579 dh = skb_header_pointer(skb, dataoff,
sizeof(_dh), &dh);
581 msg =
"nf_ct_dccp: short packet ";
587 msg =
"nf_ct_dccp: truncated/malformed packet ";
592 if (dh->dccph_cscov) {
593 cscov = (dh->dccph_cscov - 1) * 4;
594 if (cscov > dccp_len) {
595 msg =
"nf_ct_dccp: bad checksum coverage ";
601 nf_checksum_partial(skb, hooknum, dataoff, cscov,
IPPROTO_DCCP,
603 msg =
"nf_ct_dccp: bad checksum ";
608 msg =
"nf_ct_dccp: reserved packet type ";
620 static int dccp_print_tuple(
struct seq_file *
s,
628 static int dccp_print_conntrack(
struct seq_file *s,
struct nf_conn *ct)
633 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
637 struct nlattr *nest_parms;
639 spin_lock_bh(&ct->
lock);
642 goto nla_put_failure;
648 goto nla_put_failure;
649 nla_nest_end(skb, nest_parms);
650 spin_unlock_bh(&ct->
lock);
654 spin_unlock_bh(&ct->
lock);
685 spin_lock_bh(&ct->
lock);
686 ct->
proto.
dccp.state = nla_get_u8(tb[CTA_PROTOINFO_DCCP_STATE]);
696 be64_to_cpu(nla_get_be64(tb[CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ]));
698 spin_unlock_bh(&ct->
lock);
702 static int dccp_nlattr_size(
void)
704 return nla_total_size(0)
710 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
712 #include <linux/netfilter/nfnetlink.h>
715 static int dccp_timeout_nlattr_to_obj(
struct nlattr *tb[],
716 struct net *net,
void *
data)
718 struct dccp_net *dn = dccp_pernet(net);
719 unsigned int *timeouts =
data;
729 timeouts[
i] =
ntohl(nla_get_be32(tb[i])) *
HZ;
736 dccp_timeout_obj_to_nlattr(
struct sk_buff *skb,
const void *data)
738 const unsigned int *timeouts =
data;
742 if (nla_put_be32(skb, i,
htonl(timeouts[i] /
HZ)))
743 goto nla_put_failure;
752 dccp_timeout_nla_policy[CTA_TIMEOUT_DCCP_MAX+1] = {
765 static struct ctl_table dccp_sysctl_table[] = {
767 .
procname =
"nf_conntrack_dccp_timeout_request",
768 .maxlen =
sizeof(
unsigned int),
773 .procname =
"nf_conntrack_dccp_timeout_respond",
774 .maxlen =
sizeof(
unsigned int),
779 .procname =
"nf_conntrack_dccp_timeout_partopen",
780 .maxlen =
sizeof(
unsigned int),
785 .procname =
"nf_conntrack_dccp_timeout_open",
786 .maxlen =
sizeof(
unsigned int),
791 .procname =
"nf_conntrack_dccp_timeout_closereq",
792 .maxlen =
sizeof(
unsigned int),
797 .procname =
"nf_conntrack_dccp_timeout_closing",
798 .maxlen =
sizeof(
unsigned int),
803 .procname =
"nf_conntrack_dccp_timeout_timewait",
804 .maxlen =
sizeof(
unsigned int),
809 .procname =
"nf_conntrack_dccp_loose",
810 .maxlen =
sizeof(
int),
825 pn->ctl_table =
kmemdup(dccp_sysctl_table,
826 sizeof(dccp_sysctl_table),
845 struct dccp_net *dn = dccp_pernet(net);
860 return dccp_kmemdup_sysctl_table(pn, dn);
867 .pkt_to_tuple = dccp_pkt_to_tuple,
868 .invert_tuple = dccp_invert_tuple,
870 .packet = dccp_packet,
871 .get_timeouts = dccp_get_timeouts,
873 .print_tuple = dccp_print_tuple,
874 .print_conntrack = dccp_print_conntrack,
875 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
876 .to_nlattr = dccp_to_nlattr,
877 .nlattr_size = dccp_nlattr_size,
878 .from_nlattr = nlattr_to_dccp,
884 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
886 .nlattr_to_obj = dccp_timeout_nlattr_to_obj,
887 .obj_to_nlattr = dccp_timeout_obj_to_nlattr,
889 .obj_size =
sizeof(
unsigned int) * CT_DCCP_MAX,
901 .pkt_to_tuple = dccp_pkt_to_tuple,
902 .invert_tuple = dccp_invert_tuple,
904 .packet = dccp_packet,
905 .get_timeouts = dccp_get_timeouts,
907 .print_tuple = dccp_print_tuple,
908 .print_conntrack = dccp_print_conntrack,
909 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
910 .to_nlattr = dccp_to_nlattr,
911 .nlattr_size = dccp_nlattr_size,
912 .from_nlattr = nlattr_to_dccp,
918 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
920 .nlattr_to_obj = dccp_timeout_nlattr_to_obj,
921 .obj_to_nlattr = dccp_timeout_obj_to_nlattr,
923 .obj_size =
sizeof(
unsigned int) * CT_DCCP_MAX,
931 static __net_init int dccp_net_init(
struct net *net)
937 pr_err(
"nf_conntrack_l4proto_dccp4 :protocol register failed.\n");
943 pr_err(
"nf_conntrack_l4proto_dccp6 :protocol register failed.\n");
954 static __net_exit void dccp_net_exit(
struct net *net)
963 .init = dccp_net_init,
964 .exit = dccp_net_exit,
969 static int __init nf_conntrack_proto_dccp_init(
void)
974 static void __exit nf_conntrack_proto_dccp_fini(
void)