~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/netfilter/nf_nat_proto_sctp.c

Version: ~ [ linux-5.9-rc6 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Public License version 2 as
  6  * published by the Free Software Foundation.
  7  */
  8 
  9 #include <linux/types.h>
 10 #include <linux/init.h>
 11 #include <linux/sctp.h>
 12 #include <linux/module.h>
 13 #include <net/sctp/checksum.h>
 14 
 15 #include <net/netfilter/nf_nat_l4proto.h>
 16 
 17 static u_int16_t nf_sctp_port_rover;
 18 
 19 static void
 20 sctp_unique_tuple(const struct nf_nat_l3proto *l3proto,
 21                   struct nf_conntrack_tuple *tuple,
 22                   const struct nf_nat_range *range,
 23                   enum nf_nat_manip_type maniptype,
 24                   const struct nf_conn *ct)
 25 {
 26         nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct,
 27                                     &nf_sctp_port_rover);
 28 }
 29 
 30 static bool
 31 sctp_manip_pkt(struct sk_buff *skb,
 32                const struct nf_nat_l3proto *l3proto,
 33                unsigned int iphdroff, unsigned int hdroff,
 34                const struct nf_conntrack_tuple *tuple,
 35                enum nf_nat_manip_type maniptype)
 36 {
 37         sctp_sctphdr_t *hdr;
 38 
 39         if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
 40                 return false;
 41 
 42         hdr = (struct sctphdr *)(skb->data + hdroff);
 43 
 44         if (maniptype == NF_NAT_MANIP_SRC) {
 45                 /* Get rid of src port */
 46                 hdr->source = tuple->src.u.sctp.port;
 47         } else {
 48                 /* Get rid of dst port */
 49                 hdr->dest = tuple->dst.u.sctp.port;
 50         }
 51 
 52         hdr->checksum = sctp_compute_cksum(skb, hdroff);
 53 
 54         return true;
 55 }
 56 
 57 static const struct nf_nat_l4proto nf_nat_l4proto_sctp = {
 58         .l4proto                = IPPROTO_SCTP,
 59         .manip_pkt              = sctp_manip_pkt,
 60         .in_range               = nf_nat_l4proto_in_range,
 61         .unique_tuple           = sctp_unique_tuple,
 62 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
 63         .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
 64 #endif
 65 };
 66 
 67 static int __init nf_nat_proto_sctp_init(void)
 68 {
 69         int err;
 70 
 71         err = nf_nat_l4proto_register(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
 72         if (err < 0)
 73                 goto err1;
 74         err = nf_nat_l4proto_register(NFPROTO_IPV6, &nf_nat_l4proto_sctp);
 75         if (err < 0)
 76                 goto err2;
 77         return 0;
 78 
 79 err2:
 80         nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
 81 err1:
 82         return err;
 83 }
 84 
 85 static void __exit nf_nat_proto_sctp_exit(void)
 86 {
 87         nf_nat_l4proto_unregister(NFPROTO_IPV6, &nf_nat_l4proto_sctp);
 88         nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
 89 }
 90 
 91 module_init(nf_nat_proto_sctp_init);
 92 module_exit(nf_nat_proto_sctp_exit);
 93 
 94 MODULE_LICENSE("GPL");
 95 MODULE_DESCRIPTION("SCTP NAT protocol helper");
 96 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
 97 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp