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

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

Version: ~ [ linux-5.13-rc1 ] ~ [ linux-5.12.2 ] ~ [ linux-5.11.19 ] ~ [ linux-5.10.35 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.117 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.190 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.232 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.268 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.268 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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 /* x_tables module for setting the IPv4/IPv6 DSCP field, Version 1.8
  2  *
  3  * (C) 2002 by Harald Welte <laforge@netfilter.org>
  4  * based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License version 2 as
  8  * published by the Free Software Foundation.
  9  *
 10  * See RFC2474 for a description of the DSCP field within the IP Header.
 11 */
 12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 13 #include <linux/module.h>
 14 #include <linux/skbuff.h>
 15 #include <linux/ip.h>
 16 #include <linux/ipv6.h>
 17 #include <net/dsfield.h>
 18 
 19 #include <linux/netfilter/x_tables.h>
 20 #include <linux/netfilter/xt_DSCP.h>
 21 
 22 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
 23 MODULE_DESCRIPTION("Xtables: DSCP/TOS field modification");
 24 MODULE_LICENSE("GPL");
 25 MODULE_ALIAS("ipt_DSCP");
 26 MODULE_ALIAS("ip6t_DSCP");
 27 MODULE_ALIAS("ipt_TOS");
 28 MODULE_ALIAS("ip6t_TOS");
 29 
 30 static unsigned int
 31 dscp_tg(struct sk_buff *skb, const struct xt_action_param *par)
 32 {
 33         const struct xt_DSCP_info *dinfo = par->targinfo;
 34         u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
 35 
 36         if (dscp != dinfo->dscp) {
 37                 if (!skb_make_writable(skb, sizeof(struct iphdr)))
 38                         return NF_DROP;
 39 
 40                 ipv4_change_dsfield(ip_hdr(skb), (__u8)(~XT_DSCP_MASK),
 41                                     dinfo->dscp << XT_DSCP_SHIFT);
 42 
 43         }
 44         return XT_CONTINUE;
 45 }
 46 
 47 static unsigned int
 48 dscp_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 49 {
 50         const struct xt_DSCP_info *dinfo = par->targinfo;
 51         u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
 52 
 53         if (dscp != dinfo->dscp) {
 54                 if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
 55                         return NF_DROP;
 56 
 57                 ipv6_change_dsfield(ipv6_hdr(skb), (__u8)(~XT_DSCP_MASK),
 58                                     dinfo->dscp << XT_DSCP_SHIFT);
 59         }
 60         return XT_CONTINUE;
 61 }
 62 
 63 static int dscp_tg_check(const struct xt_tgchk_param *par)
 64 {
 65         const struct xt_DSCP_info *info = par->targinfo;
 66 
 67         if (info->dscp > XT_DSCP_MAX) {
 68                 pr_info("dscp %x out of range\n", info->dscp);
 69                 return -EDOM;
 70         }
 71         return 0;
 72 }
 73 
 74 static unsigned int
 75 tos_tg(struct sk_buff *skb, const struct xt_action_param *par)
 76 {
 77         const struct xt_tos_target_info *info = par->targinfo;
 78         struct iphdr *iph = ip_hdr(skb);
 79         u_int8_t orig, nv;
 80 
 81         orig = ipv4_get_dsfield(iph);
 82         nv   = (orig & ~info->tos_mask) ^ info->tos_value;
 83 
 84         if (orig != nv) {
 85                 if (!skb_make_writable(skb, sizeof(struct iphdr)))
 86                         return NF_DROP;
 87                 iph = ip_hdr(skb);
 88                 ipv4_change_dsfield(iph, 0, nv);
 89         }
 90 
 91         return XT_CONTINUE;
 92 }
 93 
 94 static unsigned int
 95 tos_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 96 {
 97         const struct xt_tos_target_info *info = par->targinfo;
 98         struct ipv6hdr *iph = ipv6_hdr(skb);
 99         u_int8_t orig, nv;
100 
101         orig = ipv6_get_dsfield(iph);
102         nv   = (orig & ~info->tos_mask) ^ info->tos_value;
103 
104         if (orig != nv) {
105                 if (!skb_make_writable(skb, sizeof(struct iphdr)))
106                         return NF_DROP;
107                 iph = ipv6_hdr(skb);
108                 ipv6_change_dsfield(iph, 0, nv);
109         }
110 
111         return XT_CONTINUE;
112 }
113 
114 static struct xt_target dscp_tg_reg[] __read_mostly = {
115         {
116                 .name           = "DSCP",
117                 .family         = NFPROTO_IPV4,
118                 .checkentry     = dscp_tg_check,
119                 .target         = dscp_tg,
120                 .targetsize     = sizeof(struct xt_DSCP_info),
121                 .table          = "mangle",
122                 .me             = THIS_MODULE,
123         },
124         {
125                 .name           = "DSCP",
126                 .family         = NFPROTO_IPV6,
127                 .checkentry     = dscp_tg_check,
128                 .target         = dscp_tg6,
129                 .targetsize     = sizeof(struct xt_DSCP_info),
130                 .table          = "mangle",
131                 .me             = THIS_MODULE,
132         },
133         {
134                 .name           = "TOS",
135                 .revision       = 1,
136                 .family         = NFPROTO_IPV4,
137                 .table          = "mangle",
138                 .target         = tos_tg,
139                 .targetsize     = sizeof(struct xt_tos_target_info),
140                 .me             = THIS_MODULE,
141         },
142         {
143                 .name           = "TOS",
144                 .revision       = 1,
145                 .family         = NFPROTO_IPV6,
146                 .table          = "mangle",
147                 .target         = tos_tg6,
148                 .targetsize     = sizeof(struct xt_tos_target_info),
149                 .me             = THIS_MODULE,
150         },
151 };
152 
153 static int __init dscp_tg_init(void)
154 {
155         return xt_register_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
156 }
157 
158 static void __exit dscp_tg_exit(void)
159 {
160         xt_unregister_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
161 }
162 
163 module_init(dscp_tg_init);
164 module_exit(dscp_tg_exit);
165 

~ [ 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