···223223 This allows LEDs to be initialised in the ON state.224224 If unsure, say Y.225225226226+comment "iptables trigger is under Netfilter config (LED target)"227227+ depends on LEDS_TRIGGERS228228+226229endif # NEW_LEDS
···7676extern int nfnetlink_has_listeners(unsigned int group);7777extern int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, 7878 int echo);7979+extern void nfnetlink_set_err(u32 pid, u32 group, int error);7980extern int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags);80818182extern void nfnl_lock(void);
+8-7
include/linux/netfilter/x_tables.h
···349349{350350 struct list_head list;351351352352- /* A unique name... */353353- const char name[XT_TABLE_MAXNAMELEN];354354-355352 /* What hooks you will enter on */356353 unsigned int valid_hooks;357354358355 /* Lock for the curtain */359359- rwlock_t lock;356356+ struct mutex lock;360357361358 /* Man behind the curtain... */362362- //struct ip6t_table_info *private;363363- void *private;359359+ struct xt_table_info *private;364360365361 /* Set this to THIS_MODULE if you are a module, otherwise NULL */366362 struct module *me;367363368364 u_int8_t af; /* address/protocol family */365365+366366+ /* A unique name... */367367+ const char name[XT_TABLE_MAXNAMELEN];369368};370369371370#include <linux/netfilter_ipv4.h>···385386386387 /* ipt_entry tables: one per CPU */387388 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */388388- char *entries[1];389389+ void *entries[1];389390};390391391392#define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \···432433433434extern struct xt_table_info *xt_alloc_table_info(unsigned int size);434435extern void xt_free_table_info(struct xt_table_info *info);436436+extern void xt_table_entry_swap_rcu(struct xt_table_info *old,437437+ struct xt_table_info *new);435438436439#ifdef CONFIG_COMPAT437440#include <net/compat.h>
+13
include/linux/netfilter/xt_LED.h
···11+#ifndef _XT_LED_H22+#define _XT_LED_H33+44+struct xt_led_info {55+ char id[27]; /* Unique ID for this trigger in the LED class */66+ __u8 always_blink; /* Blink even if the LED is already on */77+ __u32 delay; /* Delay until LED is switched off after trigger */88+99+ /* Kernel data used in the module */1010+ void *internal_data __attribute__((aligned(8)));1111+};1212+1313+#endif /* _XT_LED_H */
···44/* timings are in milliseconds. */55#define XT_LIMIT_SCALE 100006677+struct xt_limit_priv;88+79/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490810 seconds, or one every 59 hours. */911struct xt_rateinfo {···1311 u_int32_t burst; /* Period multiplier for upper limit. */14121513 /* Used internally by the kernel */1616- unsigned long prev;1717- u_int32_t credit;1414+ unsigned long prev; /* moved to xt_limit_priv */1515+ u_int32_t credit; /* moved to xt_limit_priv */1816 u_int32_t credit_cap, cost;19172020- /* Ugly, ugly fucker. */2121- struct xt_rateinfo *master;1818+ struct xt_limit_priv *master;2219};2320#endif /*_XT_RATE_H*/
+3-1
include/linux/netfilter/xt_quota.h
···66};77#define XT_QUOTA_MASK 0x18899+struct xt_quota_priv;1010+911struct xt_quota_info {1012 u_int32_t flags;1113 u_int32_t pad;12141315 /* Used internally by the kernel */1416 aligned_u64 quota;1515- struct xt_quota_info *master;1717+ struct xt_quota_priv *master;1618};17191820#endif /* _XT_QUOTA_H */
···3131 default y3232 help3333 This option enables /proc and sysctl compatibility with the old3434- layer 3 dependant connection tracking. This is needed to keep3434+ layer 3 dependent connection tracking. This is needed to keep3535 old programs that have not been adapted to the new names working.36363737 If unsure, say Y.···9595config IP_NF_MATCH_TTL9696 tristate '"ttl" match support'9797 depends on NETFILTER_ADVANCED9898- help9999- This adds CONFIG_IP_NF_MATCH_TTL option, which enabled the user100100- to match packets by their TTL value.101101-102102- To compile it as a module, choose M here. If unsure, say N.9898+ select NETFILTER_XT_MATCH_HL9999+ ---help---100100+ This is a backwards-compat option for the user's convenience101101+ (e.g. when running oldconfig). It selects102102+ CONFIG_NETFILTER_XT_MATCH_HL.103103104104# `filter', generic and specific targets105105config IP_NF_FILTER···323323 To compile it as a module, choose M here. If unsure, say N.324324325325config IP_NF_TARGET_TTL326326- tristate 'TTL target support'327327- depends on IP_NF_MANGLE326326+ tristate '"TTL" target support'328327 depends on NETFILTER_ADVANCED329329- help330330- This option adds a `TTL' target, which enables the user to modify331331- the TTL value of the IP header.332332-333333- While it is safe to decrement/lower the TTL, this target also enables334334- functionality to increment and set the TTL value of the IP header to335335- arbitrary values. This is EXTREMELY DANGEROUS since you can easily336336- create immortal packets that loop forever on the network.337337-338338- To compile it as a module, choose M here. If unsure, say N.328328+ select NETFILTER_XT_TARGET_HL329329+ ---help---330330+ This is a backwards-compat option for the user's convenience331331+ (e.g. when running oldconfig). It selects332332+ CONFIG_NETFILTER_XT_TARGET_HL.339333340334# raw + specific targets341335config IP_NF_RAW
···11-/* IP tables module for matching the value of the TTL22- *33- * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>44- *55- * This program is free software; you can redistribute it and/or modify66- * it under the terms of the GNU General Public License version 2 as77- * published by the Free Software Foundation.88- */99-1010-#include <linux/ip.h>1111-#include <linux/module.h>1212-#include <linux/skbuff.h>1313-1414-#include <linux/netfilter_ipv4/ipt_ttl.h>1515-#include <linux/netfilter/x_tables.h>1616-1717-MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");1818-MODULE_DESCRIPTION("Xtables: IPv4 TTL field match");1919-MODULE_LICENSE("GPL");2020-2121-static bool ttl_mt(const struct sk_buff *skb, const struct xt_match_param *par)2222-{2323- const struct ipt_ttl_info *info = par->matchinfo;2424- const u8 ttl = ip_hdr(skb)->ttl;2525-2626- switch (info->mode) {2727- case IPT_TTL_EQ:2828- return ttl == info->ttl;2929- case IPT_TTL_NE:3030- return ttl != info->ttl;3131- case IPT_TTL_LT:3232- return ttl < info->ttl;3333- case IPT_TTL_GT:3434- return ttl > info->ttl;3535- default:3636- printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",3737- info->mode);3838- return false;3939- }4040-4141- return false;4242-}4343-4444-static struct xt_match ttl_mt_reg __read_mostly = {4545- .name = "ttl",4646- .family = NFPROTO_IPV4,4747- .match = ttl_mt,4848- .matchsize = sizeof(struct ipt_ttl_info),4949- .me = THIS_MODULE,5050-};5151-5252-static int __init ttl_mt_init(void)5353-{5454- return xt_register_match(&ttl_mt_reg);5555-}5656-5757-static void __exit ttl_mt_exit(void)5858-{5959- xt_unregister_match(&ttl_mt_reg);6060-}6161-6262-module_init(ttl_mt_init);6363-module_exit(ttl_mt_exit);
···120120 typeof(nf_nat_seq_adjust_hook) seq_adjust;121121122122 seq_adjust = rcu_dereference(nf_nat_seq_adjust_hook);123123- if (!seq_adjust || !seq_adjust(skb, ct, ctinfo))123123+ if (!seq_adjust || !seq_adjust(skb, ct, ctinfo)) {124124+ NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);124125 return NF_DROP;126126+ }125127 }126128out:127129 /* We've seen it coming out the other side: confirm it */
···9595 To compile it as a module, choose M here. If unsure, say N.96969797config IP6_NF_MATCH_HL9898- tristate '"hl" match support'9898+ tristate '"hl" hoplimit match support'9999 depends on NETFILTER_ADVANCED100100- help101101- HL matching allows you to match packets based on the hop102102- limit of the packet.103103-104104- To compile it as a module, choose M here. If unsure, say N.100100+ select NETFILTER_XT_MATCH_HL101101+ ---help---102102+ This is a backwards-compat option for the user's convenience103103+ (e.g. when running oldconfig). It selects104104+ COFNIG_NETFILTER_XT_MATCH_HL.105105106106config IP6_NF_MATCH_IPV6HEADER107107 tristate '"ipv6header" IPv6 Extension Headers Match'···130130 To compile it as a module, choose M here. If unsure, say N.131131132132# The targets133133+config IP6_NF_TARGET_HL134134+ tristate '"HL" hoplimit target support'135135+ depends on NETFILTER_ADVANCED136136+ select NETFILTER_XT_TARGET_HL137137+ ---help---138138+ This is a backwards-compat option for the user's convenience139139+ (e.g. when running oldconfig). It selects140140+ COFNIG_NETFILTER_XT_TARGET_HL.141141+133142config IP6_NF_TARGET_LOG134143 tristate "LOG target support"135144 default m if NETFILTER_ADVANCED=n···176167 This option adds a `mangle' table to iptables: see the man page for177168 iptables(8). This table is used for various packet alterations178169 which can effect how the packet is routed.179179-180180- To compile it as a module, choose M here. If unsure, say N.181181-182182-config IP6_NF_TARGET_HL183183- tristate 'HL (hoplimit) target support'184184- depends on IP6_NF_MANGLE185185- depends on NETFILTER_ADVANCED186186- help187187- This option adds a `HL' target, which enables the user to decrement188188- the hoplimit value of the IPv6 header or set it to a given (lower)189189- value.190190-191191- While it is safe to decrement the hoplimit value, this option also192192- enables functionality to increment and set the hoplimit value of the193193- IPv6 header to arbitrary values. This is EXTREMELY DANGEROUS since194194- you can easily create immortal packets that loop forever on the195195- network.196170197171 To compile it as a module, choose M here. If unsure, say N.198172
···126126 pr_debug("icmpv6: can't create new conn with type %u\n",127127 type + 128);128128 nf_ct_dump_tuple_ipv6(&ct->tuplehash[0].tuple);129129+ if (LOG_INVALID(nf_ct_net(ct), IPPROTO_ICMPV6))130130+ nf_log_packet(PF_INET6, 0, skb, NULL, NULL, NULL,131131+ "nf_ct_icmpv6: invalid new with type %d ",132132+ type + 128);129133 return false;130134 }131135 atomic_set(&ct->proto.icmp.count, 0);
+63
net/netfilter/Kconfig
···357357358358 To compile it as a module, choose M here. If unsure, say N.359359360360+config NETFILTER_XT_TARGET_HL361361+ tristate '"HL" hoplimit target support'362362+ depends on IP_NF_MANGLE || IP6_NF_MANGLE363363+ depends on NETFILTER_ADVANCED364364+ ---help---365365+ This option adds the "HL" (for IPv6) and "TTL" (for IPv4)366366+ targets, which enable the user to change the367367+ hoplimit/time-to-live value of the IP header.368368+369369+ While it is safe to decrement the hoplimit/TTL value, the370370+ modules also allow to increment and set the hoplimit value of371371+ the header to arbitrary values. This is EXTREMELY DANGEROUS372372+ since you can easily create immortal packets that loop373373+ forever on the network.374374+375375+config NETFILTER_XT_TARGET_LED376376+ tristate '"LED" target support'377377+ depends on LEDS_CLASS378378+ depends on NETFILTER_ADVANCED379379+ help380380+ This option adds a `LED' target, which allows you to blink LEDs in381381+ response to particular packets passing through your machine.382382+383383+ This can be used to turn a spare LED into a network activity LED,384384+ which only flashes in response to FTP transfers, for example. Or385385+ you could have an LED which lights up for a minute or two every time386386+ somebody connects to your machine via SSH.387387+388388+ You will need support for the "led" class to make this work.389389+390390+ To create an LED trigger for incoming SSH traffic:391391+ iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000392392+393393+ Then attach the new trigger to an LED on your system:394394+ echo netfilter-ssh > /sys/class/leds/<ledname>/trigger395395+396396+ For more information on the LEDs available on your system, see397397+ Documentation/leds-class.txt398398+360399config NETFILTER_XT_TARGET_MARK361400 tristate '"MARK" target support'362401 default m if NETFILTER_ADVANCED=n···527488 This option adds a "TCPOPTSTRIP" target, which allows you to strip528489 TCP options from TCP packets.529490491491+config NETFILTER_XT_MATCH_CLUSTER492492+ tristate '"cluster" match support'493493+ depends on NF_CONNTRACK494494+ depends on NETFILTER_ADVANCED495495+ ---help---496496+ This option allows you to build work-load-sharing clusters of497497+ network servers/stateful firewalls without having a dedicated498498+ load-balancing router/server/switch. Basically, this match returns499499+ true when the packet must be handled by this cluster node. Thus,500500+ all nodes see all packets and this match decides which node handles501501+ what packets. The work-load sharing algorithm is based on source502502+ address hashing.503503+504504+ If you say Y or M here, try `iptables -m cluster --help` for505505+ more information.506506+530507config NETFILTER_XT_MATCH_COMMENT531508 tristate '"comment" match support'532509 depends on NETFILTER_ADVANCED···659604 tracked by a conntrack-helper, ie. ip_conntrack_ftp660605661606 To compile it as a module, choose M here. If unsure, say Y.607607+608608+config NETFILTER_XT_MATCH_HL609609+ tristate '"hl" hoplimit/TTL match support'610610+ depends on NETFILTER_ADVANCED611611+ ---help---612612+ HL matching allows you to match packets based on the hoplimit613613+ in the IPv6 header, or the time-to-live field in the IPv4614614+ header of the packet.662615663616config NETFILTER_XT_MATCH_IPRANGE664617 tristate '"iprange" address range match support'
···174174 outdev, &elem, okfn, hook_thresh);175175 if (verdict == NF_ACCEPT || verdict == NF_STOP) {176176 ret = 1;177177- goto unlock;178177 } else if (verdict == NF_DROP) {179178 kfree_skb(skb);180179 ret = -EPERM;···182183 verdict >> NF_VERDICT_BITS))183184 goto next_hook;184185 }185185-unlock:186186 rcu_read_unlock();187187 return ret;188188}
+9-5
net/netfilter/nf_conntrack_core.c
···5454unsigned int nf_conntrack_htable_size __read_mostly;5555EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);56565757-int nf_conntrack_max __read_mostly;5757+unsigned int nf_conntrack_max __read_mostly;5858EXPORT_SYMBOL_GPL(nf_conntrack_max);59596060struct nf_conn nf_conntrack_untracked __read_mostly;···472472 struct nf_conn *ct;473473474474 if (unlikely(!nf_conntrack_hash_rnd_initted)) {475475- get_random_bytes(&nf_conntrack_hash_rnd, 4);475475+ get_random_bytes(&nf_conntrack_hash_rnd,476476+ sizeof(nf_conntrack_hash_rnd));476477 nf_conntrack_hash_rnd_initted = 1;477478 }478479···517516static void nf_conntrack_free_rcu(struct rcu_head *head)518517{519518 struct nf_conn *ct = container_of(head, struct nf_conn, rcu);520520- struct net *net = nf_ct_net(ct);521519522520 nf_ct_ext_free(ct);523521 kmem_cache_free(nf_conntrack_cachep, ct);524524- atomic_dec(&net->ct.count);525522}526523527524void nf_conntrack_free(struct nf_conn *ct)528525{526526+ struct net *net = nf_ct_net(ct);527527+529528 nf_ct_ext_destroy(ct);529529+ atomic_dec(&net->ct.count);530530 call_rcu(&ct->rcu, nf_conntrack_free_rcu);531531}532532EXPORT_SYMBOL_GPL(nf_conntrack_free);···735733 nf_conntrack_put(skb->nfct);736734 skb->nfct = NULL;737735 NF_CT_STAT_INC_ATOMIC(net, invalid);736736+ if (ret == -NF_DROP)737737+ NF_CT_STAT_INC_ATOMIC(net, drop);738738 return -ret;739739 }740740···1107110311081104 /* We have to rehahs for the new table anyway, so we also can11091105 * use a newrandom seed */11101110- get_random_bytes(&rnd, 4);11061106+ get_random_bytes(&rnd, sizeof(rnd));1111110711121108 /* Lookups in the old hash might happen in parallel, which means we11131109 * might get false negatives during connection lookup. New connections
+2-1
net/netfilter/nf_conntrack_expect.c
···7272 unsigned int hash;73737474 if (unlikely(!nf_ct_expect_hash_rnd_initted)) {7575- get_random_bytes(&nf_ct_expect_hash_rnd, 4);7575+ get_random_bytes(&nf_ct_expect_hash_rnd,7676+ sizeof(nf_ct_expect_hash_rnd));7677 nf_ct_expect_hash_rnd_initted = 1;7778 }7879
+72-89
net/netfilter/nf_conntrack_netlink.c
···518518nla_put_failure:519519 rcu_read_unlock();520520nlmsg_failure:521521+ nfnetlink_set_err(0, group, -ENOBUFS);521522 kfree_skb(skb);522523 return NOTIFY_DONE;523524}···600599601600 nla_parse_nested(tb, CTA_IP_MAX, attr, NULL);602601603603- l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);602602+ rcu_read_lock();603603+ l3proto = __nf_ct_l3proto_find(tuple->src.l3num);604604605605 if (likely(l3proto->nlattr_to_tuple)) {606606 ret = nla_validate_nested(attr, CTA_IP_MAX,···610608 ret = l3proto->nlattr_to_tuple(tb, tuple);611609 }612610613613- nf_ct_l3proto_put(l3proto);611611+ rcu_read_unlock();614612615613 return ret;616614}···635633 return -EINVAL;636634 tuple->dst.protonum = nla_get_u8(tb[CTA_PROTO_NUM]);637635638638- l4proto = nf_ct_l4proto_find_get(tuple->src.l3num, tuple->dst.protonum);636636+ rcu_read_lock();637637+ l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum);639638640639 if (likely(l4proto->nlattr_to_tuple)) {641640 ret = nla_validate_nested(attr, CTA_PROTO_MAX,···645642 ret = l4proto->nlattr_to_tuple(tb, tuple);646643 }647644648648- nf_ct_l4proto_put(l4proto);645645+ rcu_read_unlock();649646650647 return ret;651648}···992989993990 nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, NULL);994991995995- l4proto = nf_ct_l4proto_find_get(nf_ct_l3num(ct), nf_ct_protonum(ct));992992+ rcu_read_lock();993993+ l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));996994 if (l4proto->from_nlattr)997995 err = l4proto->from_nlattr(tb, ct);998998- nf_ct_l4proto_put(l4proto);996996+ rcu_read_unlock();9999971000998 return err;1001999}···10661062{10671063 int err;1068106410651065+ /* only allow NAT changes and master assignation for new conntracks */10661066+ if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST] || cda[CTA_TUPLE_MASTER])10671067+ return -EOPNOTSUPP;10681068+10691069 if (cda[CTA_HELP]) {10701070 err = ctnetlink_change_helper(ct, cda);10711071 if (err < 0)···11321124 report);11331125}1134112611351135-static int11271127+static struct nf_conn *11361128ctnetlink_create_conntrack(struct nlattr *cda[],11371129 struct nf_conntrack_tuple *otuple,11381130 struct nf_conntrack_tuple *rtuple,11391139- struct nf_conn *master_ct,11401140- u32 pid,11411141- int report)11311131+ u8 u3)11421132{11431133 struct nf_conn *ct;11441134 int err = -EINVAL;···1144113811451139 ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC);11461140 if (IS_ERR(ct))11471147- return -ENOMEM;11411141+ return ERR_PTR(-ENOMEM);1148114211491143 if (!cda[CTA_TIMEOUT])11501150- goto err;11441144+ goto err1;11511145 ct->timeout.expires = ntohl(nla_get_be32(cda[CTA_TIMEOUT]));1152114611531147 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;···11581152 char *helpname;1159115311601154 err = ctnetlink_parse_help(cda[CTA_HELP], &helpname);11611161- if (err < 0) {11621162- rcu_read_unlock();11631163- goto err;11641164- }11551155+ if (err < 0)11561156+ goto err2;1165115711661158 helper = __nf_conntrack_helper_find_byname(helpname);11671159 if (helper == NULL) {···11671163#ifdef CONFIG_MODULES11681164 if (request_module("nfct-helper-%s", helpname) < 0) {11691165 err = -EOPNOTSUPP;11701170- goto err;11661166+ goto err1;11711167 }1172116811731169 rcu_read_lock();11741170 helper = __nf_conntrack_helper_find_byname(helpname);11751171 if (helper) {11761176- rcu_read_unlock();11771172 err = -EAGAIN;11781178- goto err;11731173+ goto err2;11791174 }11801175 rcu_read_unlock();11811176#endif11821177 err = -EOPNOTSUPP;11831183- goto err;11781178+ goto err1;11841179 } else {11851180 struct nf_conn_help *help;1186118111871182 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);11881183 if (help == NULL) {11891189- rcu_read_unlock();11901184 err = -ENOMEM;11911191- goto err;11851185+ goto err2;11921186 }1193118711941188 /* not in hash table yet so not strictly necessary */···11951193 } else {11961194 /* try an implicit helper assignation */11971195 err = __nf_ct_try_assign_helper(ct, GFP_ATOMIC);11981198- if (err < 0) {11991199- rcu_read_unlock();12001200- goto err;12011201- }11961196+ if (err < 0)11971197+ goto err2;12021198 }1203119912041200 if (cda[CTA_STATUS]) {12051201 err = ctnetlink_change_status(ct, cda);12061206- if (err < 0) {12071207- rcu_read_unlock();12081208- goto err;12091209- }12021202+ if (err < 0)12031203+ goto err2;12101204 }1211120512121206 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {12131207 err = ctnetlink_change_nat(ct, cda);12141214- if (err < 0) {12151215- rcu_read_unlock();12161216- goto err;12171217- }12081208+ if (err < 0)12091209+ goto err2;12181210 }1219121112201212#ifdef CONFIG_NF_NAT_NEEDED12211213 if (cda[CTA_NAT_SEQ_ADJ_ORIG] || cda[CTA_NAT_SEQ_ADJ_REPLY]) {12221214 err = ctnetlink_change_nat_seq_adj(ct, cda);12231223- if (err < 0) {12241224- rcu_read_unlock();12251225- goto err;12261226- }12151215+ if (err < 0)12161216+ goto err2;12271217 }12281218#endif1229121912301220 if (cda[CTA_PROTOINFO]) {12311221 err = ctnetlink_change_protoinfo(ct, cda);12321232- if (err < 0) {12331233- rcu_read_unlock();12341234- goto err;12351235- }12221222+ if (err < 0)12231223+ goto err2;12361224 }1237122512381226 nf_ct_acct_ext_add(ct, GFP_ATOMIC);···12331241#endif1234124212351243 /* setup master conntrack: this is a confirmed expectation */12361236- if (master_ct) {12441244+ if (cda[CTA_TUPLE_MASTER]) {12451245+ struct nf_conntrack_tuple master;12461246+ struct nf_conntrack_tuple_hash *master_h;12471247+ struct nf_conn *master_ct;12481248+12491249+ err = ctnetlink_parse_tuple(cda, &master, CTA_TUPLE_MASTER, u3);12501250+ if (err < 0)12511251+ goto err2;12521252+12531253+ master_h = __nf_conntrack_find(&init_net, &master);12541254+ if (master_h == NULL) {12551255+ err = -ENOENT;12561256+ goto err2;12571257+ }12581258+ master_ct = nf_ct_tuplehash_to_ctrack(master_h);12591259+ nf_conntrack_get(&master_ct->ct_general);12371260 __set_bit(IPS_EXPECTED_BIT, &ct->status);12381261 ct->master = master_ct;12391262 }1240126312411241- nf_conntrack_get(&ct->ct_general);12421264 add_timer(&ct->timeout);12431265 nf_conntrack_hash_insert(ct);12441266 rcu_read_unlock();12451245- ctnetlink_event_report(ct, pid, report);12461246- nf_ct_put(ct);1247126712481248- return 0;12681268+ return ct;1249126912501250-err:12701270+err2:12711271+ rcu_read_unlock();12721272+err1:12511273 nf_conntrack_free(ct);12521252- return err;12741274+ return ERR_PTR(err);12531275}1254127612551277static int···12951289 h = __nf_conntrack_find(&init_net, &rtuple);1296129012971291 if (h == NULL) {12981298- struct nf_conntrack_tuple master;12991299- struct nf_conntrack_tuple_hash *master_h = NULL;13001300- struct nf_conn *master_ct = NULL;12921292+ err = -ENOENT;12931293+ if (nlh->nlmsg_flags & NLM_F_CREATE) {12941294+ struct nf_conn *ct;1301129513021302- if (cda[CTA_TUPLE_MASTER]) {13031303- err = ctnetlink_parse_tuple(cda,13041304- &master,13051305- CTA_TUPLE_MASTER,13061306- u3);13071307- if (err < 0)13081308- goto out_unlock;13091309-13101310- master_h = __nf_conntrack_find(&init_net, &master);13111311- if (master_h == NULL) {13121312- err = -ENOENT;12961296+ ct = ctnetlink_create_conntrack(cda, &otuple,12971297+ &rtuple, u3);12981298+ if (IS_ERR(ct)) {12991299+ err = PTR_ERR(ct);13131300 goto out_unlock;13141301 }13151315- master_ct = nf_ct_tuplehash_to_ctrack(master_h);13161316- nf_conntrack_get(&master_ct->ct_general);13171317- }13181318-13191319- err = -ENOENT;13201320- if (nlh->nlmsg_flags & NLM_F_CREATE)13211321- err = ctnetlink_create_conntrack(cda,13221322- &otuple,13231323- &rtuple,13241324- master_ct,13251325- NETLINK_CB(skb).pid,13261326- nlmsg_report(nlh));13271327- spin_unlock_bh(&nf_conntrack_lock);13281328- if (err < 0 && master_ct)13291329- nf_ct_put(master_ct);13021302+ err = 0;13031303+ nf_conntrack_get(&ct->ct_general);13041304+ spin_unlock_bh(&nf_conntrack_lock);13051305+ ctnetlink_event_report(ct,13061306+ NETLINK_CB(skb).pid,13071307+ nlmsg_report(nlh));13081308+ nf_ct_put(ct);13091309+ } else13101310+ spin_unlock_bh(&nf_conntrack_lock);1330131113311312 return err;13321313 }···13241331 err = -EEXIST;13251332 if (!(nlh->nlmsg_flags & NLM_F_EXCL)) {13261333 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);13271327-13281328- /* we only allow nat config for new conntracks */13291329- if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST]) {13301330- err = -EOPNOTSUPP;13311331- goto out_unlock;13321332- }13331333- /* can't link an existing conntrack to a master */13341334- if (cda[CTA_TUPLE_MASTER]) {13351335- err = -EOPNOTSUPP;13361336- goto out_unlock;13371337- }1338133413391335 err = ctnetlink_change_conntrack(ct, cda);13401336 if (err == 0) {···15151533nla_put_failure:15161534 rcu_read_unlock();15171535nlmsg_failure:15361536+ nfnetlink_set_err(0, 0, -ENOBUFS);15181537 kfree_skb(skb);15191538 return NOTIFY_DONE;15201539}
-21
net/netfilter/nf_conntrack_proto.c
···74747575/* this is guaranteed to always return a valid protocol helper, since7676 * it falls back to generic_protocol */7777-struct nf_conntrack_l4proto *7878-nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t l4proto)7979-{8080- struct nf_conntrack_l4proto *p;8181-8282- rcu_read_lock();8383- p = __nf_ct_l4proto_find(l3proto, l4proto);8484- if (!try_module_get(p->me))8585- p = &nf_conntrack_l4proto_generic;8686- rcu_read_unlock();8787-8888- return p;8989-}9090-EXPORT_SYMBOL_GPL(nf_ct_l4proto_find_get);9191-9292-void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p)9393-{9494- module_put(p->me);9595-}9696-EXPORT_SYMBOL_GPL(nf_ct_l4proto_put);9797-9877struct nf_conntrack_l3proto *9978nf_ct_l3proto_find_get(u_int16_t l3proto)10079{
···625625}626626EXPORT_SYMBOL(xt_free_table_info);627627628628+void xt_table_entry_swap_rcu(struct xt_table_info *oldinfo,629629+ struct xt_table_info *newinfo)630630+{631631+ unsigned int cpu;632632+633633+ for_each_possible_cpu(cpu) {634634+ void *p = oldinfo->entries[cpu];635635+ rcu_assign_pointer(oldinfo->entries[cpu], newinfo->entries[cpu]);636636+ newinfo->entries[cpu] = p;637637+ }638638+639639+}640640+EXPORT_SYMBOL_GPL(xt_table_entry_swap_rcu);641641+628642/* Find table by name, grabs mutex & ref. Returns ERR_PTR() on error. */629643struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,630644 const char *name)···685671 struct xt_table_info *oldinfo, *private;686672687673 /* Do the substitution. */688688- write_lock_bh(&table->lock);674674+ mutex_lock(&table->lock);689675 private = table->private;690676 /* Check inside lock: is the old number correct? */691677 if (num_counters != private->number) {692678 duprintf("num_counters != table->private->number (%u/%u)\n",693679 num_counters, private->number);694694- write_unlock_bh(&table->lock);680680+ mutex_unlock(&table->lock);695681 *error = -EAGAIN;696682 return NULL;697683 }698684 oldinfo = private;699699- table->private = newinfo;685685+ rcu_assign_pointer(table->private, newinfo);700686 newinfo->initial_entries = oldinfo->initial_entries;701701- write_unlock_bh(&table->lock);687687+ mutex_unlock(&table->lock);702688689689+ synchronize_net();703690 return oldinfo;704691}705692EXPORT_SYMBOL_GPL(xt_replace_table);···734719735720 /* Simplifies replace_table code. */736721 table->private = bootstrap;737737- rwlock_init(&table->lock);722722+ mutex_init(&table->lock);723723+738724 if (!xt_replace_table(table, 0, newinfo, &ret))739725 goto unlock;740726
+171
net/netfilter/xt_HL.c
···11+/*22+ * TTL modification target for IP tables33+ * (C) 2000,2005 by Harald Welte <laforge@netfilter.org>44+ *55+ * Hop Limit modification target for ip6tables66+ * Maciej Soltysiak <solt@dns.toxicfilms.tv>77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+1313+#include <linux/module.h>1414+#include <linux/skbuff.h>1515+#include <linux/ip.h>1616+#include <linux/ipv6.h>1717+#include <net/checksum.h>1818+1919+#include <linux/netfilter/x_tables.h>2020+#include <linux/netfilter_ipv4/ipt_TTL.h>2121+#include <linux/netfilter_ipv6/ip6t_HL.h>2222+2323+MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");2424+MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");2525+MODULE_DESCRIPTION("Xtables: Hoplimit/TTL Limit field modification target");2626+MODULE_LICENSE("GPL");2727+2828+static unsigned int2929+ttl_tg(struct sk_buff *skb, const struct xt_target_param *par)3030+{3131+ struct iphdr *iph;3232+ const struct ipt_TTL_info *info = par->targinfo;3333+ int new_ttl;3434+3535+ if (!skb_make_writable(skb, skb->len))3636+ return NF_DROP;3737+3838+ iph = ip_hdr(skb);3939+4040+ switch (info->mode) {4141+ case IPT_TTL_SET:4242+ new_ttl = info->ttl;4343+ break;4444+ case IPT_TTL_INC:4545+ new_ttl = iph->ttl + info->ttl;4646+ if (new_ttl > 255)4747+ new_ttl = 255;4848+ break;4949+ case IPT_TTL_DEC:5050+ new_ttl = iph->ttl - info->ttl;5151+ if (new_ttl < 0)5252+ new_ttl = 0;5353+ break;5454+ default:5555+ new_ttl = iph->ttl;5656+ break;5757+ }5858+5959+ if (new_ttl != iph->ttl) {6060+ csum_replace2(&iph->check, htons(iph->ttl << 8),6161+ htons(new_ttl << 8));6262+ iph->ttl = new_ttl;6363+ }6464+6565+ return XT_CONTINUE;6666+}6767+6868+static unsigned int6969+hl_tg6(struct sk_buff *skb, const struct xt_target_param *par)7070+{7171+ struct ipv6hdr *ip6h;7272+ const struct ip6t_HL_info *info = par->targinfo;7373+ int new_hl;7474+7575+ if (!skb_make_writable(skb, skb->len))7676+ return NF_DROP;7777+7878+ ip6h = ipv6_hdr(skb);7979+8080+ switch (info->mode) {8181+ case IP6T_HL_SET:8282+ new_hl = info->hop_limit;8383+ break;8484+ case IP6T_HL_INC:8585+ new_hl = ip6h->hop_limit + info->hop_limit;8686+ if (new_hl > 255)8787+ new_hl = 255;8888+ break;8989+ case IP6T_HL_DEC:9090+ new_hl = ip6h->hop_limit - info->hop_limit;9191+ if (new_hl < 0)9292+ new_hl = 0;9393+ break;9494+ default:9595+ new_hl = ip6h->hop_limit;9696+ break;9797+ }9898+9999+ ip6h->hop_limit = new_hl;100100+101101+ return XT_CONTINUE;102102+}103103+104104+static bool ttl_tg_check(const struct xt_tgchk_param *par)105105+{106106+ const struct ipt_TTL_info *info = par->targinfo;107107+108108+ if (info->mode > IPT_TTL_MAXMODE) {109109+ printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",110110+ info->mode);111111+ return false;112112+ }113113+ if (info->mode != IPT_TTL_SET && info->ttl == 0)114114+ return false;115115+ return true;116116+}117117+118118+static bool hl_tg6_check(const struct xt_tgchk_param *par)119119+{120120+ const struct ip6t_HL_info *info = par->targinfo;121121+122122+ if (info->mode > IP6T_HL_MAXMODE) {123123+ printk(KERN_WARNING "ip6t_HL: invalid or unknown Mode %u\n",124124+ info->mode);125125+ return false;126126+ }127127+ if (info->mode != IP6T_HL_SET && info->hop_limit == 0) {128128+ printk(KERN_WARNING "ip6t_HL: increment/decrement doesn't "129129+ "make sense with value 0\n");130130+ return false;131131+ }132132+ return true;133133+}134134+135135+static struct xt_target hl_tg_reg[] __read_mostly = {136136+ {137137+ .name = "TTL",138138+ .revision = 0,139139+ .family = NFPROTO_IPV4,140140+ .target = ttl_tg,141141+ .targetsize = sizeof(struct ipt_TTL_info),142142+ .table = "mangle",143143+ .checkentry = ttl_tg_check,144144+ .me = THIS_MODULE,145145+ },146146+ {147147+ .name = "HL",148148+ .revision = 0,149149+ .family = NFPROTO_IPV6,150150+ .target = hl_tg6,151151+ .targetsize = sizeof(struct ip6t_HL_info),152152+ .table = "mangle",153153+ .checkentry = hl_tg6_check,154154+ .me = THIS_MODULE,155155+ },156156+};157157+158158+static int __init hl_tg_init(void)159159+{160160+ return xt_register_targets(hl_tg_reg, ARRAY_SIZE(hl_tg_reg));161161+}162162+163163+static void __exit hl_tg_exit(void)164164+{165165+ xt_unregister_targets(hl_tg_reg, ARRAY_SIZE(hl_tg_reg));166166+}167167+168168+module_init(hl_tg_init);169169+module_exit(hl_tg_exit);170170+MODULE_ALIAS("ipt_TTL");171171+MODULE_ALIAS("ip6t_HL");
+161
net/netfilter/xt_LED.c
···11+/*22+ * xt_LED.c - netfilter target to make LEDs blink upon packet matches33+ *44+ * Copyright (C) 2008 Adam Nielsen <a.nielsen@shikadi.net>55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; version 2 of the License.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program; if not, write to the Free Software1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA1818+ * 02110-1301 USA.1919+ *2020+ */2121+2222+#include <linux/module.h>2323+#include <linux/skbuff.h>2424+#include <linux/netfilter/x_tables.h>2525+#include <linux/leds.h>2626+#include <linux/mutex.h>2727+2828+#include <linux/netfilter/xt_LED.h>2929+3030+MODULE_LICENSE("GPL");3131+MODULE_AUTHOR("Adam Nielsen <a.nielsen@shikadi.net>");3232+MODULE_DESCRIPTION("Xtables: trigger LED devices on packet match");3333+3434+/*3535+ * This is declared in here (the kernel module) only, to avoid having these3636+ * dependencies in userspace code. This is what xt_led_info.internal_data3737+ * points to.3838+ */3939+struct xt_led_info_internal {4040+ struct led_trigger netfilter_led_trigger;4141+ struct timer_list timer;4242+};4343+4444+static unsigned int4545+led_tg(struct sk_buff *skb, const struct xt_target_param *par)4646+{4747+ const struct xt_led_info *ledinfo = par->targinfo;4848+ struct xt_led_info_internal *ledinternal = ledinfo->internal_data;4949+5050+ /*5151+ * If "always blink" is enabled, and there's still some time until the5252+ * LED will switch off, briefly switch it off now.5353+ */5454+ if ((ledinfo->delay > 0) && ledinfo->always_blink &&5555+ timer_pending(&ledinternal->timer))5656+ led_trigger_event(&ledinternal->netfilter_led_trigger,LED_OFF);5757+5858+ led_trigger_event(&ledinternal->netfilter_led_trigger, LED_FULL);5959+6060+ /* If there's a positive delay, start/update the timer */6161+ if (ledinfo->delay > 0) {6262+ mod_timer(&ledinternal->timer,6363+ jiffies + msecs_to_jiffies(ledinfo->delay));6464+6565+ /* Otherwise if there was no delay given, blink as fast as possible */6666+ } else if (ledinfo->delay == 0) {6767+ led_trigger_event(&ledinternal->netfilter_led_trigger, LED_OFF);6868+ }6969+7070+ /* else the delay is negative, which means switch on and stay on */7171+7272+ return XT_CONTINUE;7373+}7474+7575+static void led_timeout_callback(unsigned long data)7676+{7777+ struct xt_led_info *ledinfo = (struct xt_led_info *)data;7878+ struct xt_led_info_internal *ledinternal = ledinfo->internal_data;7979+8080+ led_trigger_event(&ledinternal->netfilter_led_trigger, LED_OFF);8181+}8282+8383+static bool led_tg_check(const struct xt_tgchk_param *par)8484+{8585+ struct xt_led_info *ledinfo = par->targinfo;8686+ struct xt_led_info_internal *ledinternal;8787+ int err;8888+8989+ if (ledinfo->id[0] == '\0') {9090+ printk(KERN_ERR KBUILD_MODNAME ": No 'id' parameter given.\n");9191+ return false;9292+ }9393+9494+ ledinternal = kzalloc(sizeof(struct xt_led_info_internal), GFP_KERNEL);9595+ if (!ledinternal) {9696+ printk(KERN_CRIT KBUILD_MODNAME ": out of memory\n");9797+ return false;9898+ }9999+100100+ ledinternal->netfilter_led_trigger.name = ledinfo->id;101101+102102+ err = led_trigger_register(&ledinternal->netfilter_led_trigger);103103+ if (err) {104104+ printk(KERN_CRIT KBUILD_MODNAME105105+ ": led_trigger_register() failed\n");106106+ if (err == -EEXIST)107107+ printk(KERN_ERR KBUILD_MODNAME108108+ ": Trigger name is already in use.\n");109109+ goto exit_alloc;110110+ }111111+112112+ /* See if we need to set up a timer */113113+ if (ledinfo->delay > 0)114114+ setup_timer(&ledinternal->timer, led_timeout_callback,115115+ (unsigned long)ledinfo);116116+117117+ ledinfo->internal_data = ledinternal;118118+119119+ return true;120120+121121+exit_alloc:122122+ kfree(ledinternal);123123+124124+ return false;125125+}126126+127127+static void led_tg_destroy(const struct xt_tgdtor_param *par)128128+{129129+ const struct xt_led_info *ledinfo = par->targinfo;130130+ struct xt_led_info_internal *ledinternal = ledinfo->internal_data;131131+132132+ if (ledinfo->delay > 0)133133+ del_timer_sync(&ledinternal->timer);134134+135135+ led_trigger_unregister(&ledinternal->netfilter_led_trigger);136136+ kfree(ledinternal);137137+}138138+139139+static struct xt_target led_tg_reg __read_mostly = {140140+ .name = "LED",141141+ .revision = 0,142142+ .family = NFPROTO_UNSPEC,143143+ .target = led_tg,144144+ .targetsize = XT_ALIGN(sizeof(struct xt_led_info)),145145+ .checkentry = led_tg_check,146146+ .destroy = led_tg_destroy,147147+ .me = THIS_MODULE,148148+};149149+150150+static int __init led_tg_init(void)151151+{152152+ return xt_register_target(&led_tg_reg);153153+}154154+155155+static void __exit led_tg_exit(void)156156+{157157+ xt_unregister_target(&led_tg_reg);158158+}159159+160160+module_init(led_tg_init);161161+module_exit(led_tg_exit);
+164
net/netfilter/xt_cluster.c
···11+/*22+ * (C) 2008-2009 Pablo Neira Ayuso <pablo@netfilter.org>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ */88+#include <linux/module.h>99+#include <linux/skbuff.h>1010+#include <linux/jhash.h>1111+#include <linux/ip.h>1212+#include <net/ipv6.h>1313+1414+#include <linux/netfilter/x_tables.h>1515+#include <net/netfilter/nf_conntrack.h>1616+#include <linux/netfilter/xt_cluster.h>1717+1818+static inline u_int32_t nf_ct_orig_ipv4_src(const struct nf_conn *ct)1919+{2020+ return ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;2121+}2222+2323+static inline const void *nf_ct_orig_ipv6_src(const struct nf_conn *ct)2424+{2525+ return ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip6;2626+}2727+2828+static inline u_int32_t2929+xt_cluster_hash_ipv4(u_int32_t ip, const struct xt_cluster_match_info *info)3030+{3131+ return jhash_1word(ip, info->hash_seed);3232+}3333+3434+static inline u_int32_t3535+xt_cluster_hash_ipv6(const void *ip, const struct xt_cluster_match_info *info)3636+{3737+ return jhash2(ip, NF_CT_TUPLE_L3SIZE / sizeof(__u32), info->hash_seed);3838+}3939+4040+static inline u_int32_t4141+xt_cluster_hash(const struct nf_conn *ct,4242+ const struct xt_cluster_match_info *info)4343+{4444+ u_int32_t hash = 0;4545+4646+ switch(nf_ct_l3num(ct)) {4747+ case AF_INET:4848+ hash = xt_cluster_hash_ipv4(nf_ct_orig_ipv4_src(ct), info);4949+ break;5050+ case AF_INET6:5151+ hash = xt_cluster_hash_ipv6(nf_ct_orig_ipv6_src(ct), info);5252+ break;5353+ default:5454+ WARN_ON(1);5555+ break;5656+ }5757+ return (((u64)hash * info->total_nodes) >> 32);5858+}5959+6060+static inline bool6161+xt_cluster_is_multicast_addr(const struct sk_buff *skb, u_int8_t family)6262+{6363+ bool is_multicast = false;6464+6565+ switch(family) {6666+ case NFPROTO_IPV4:6767+ is_multicast = ipv4_is_multicast(ip_hdr(skb)->daddr);6868+ break;6969+ case NFPROTO_IPV6:7070+ is_multicast = ipv6_addr_type(&ipv6_hdr(skb)->daddr) &7171+ IPV6_ADDR_MULTICAST;7272+ break;7373+ default:7474+ WARN_ON(1);7575+ break;7676+ }7777+ return is_multicast;7878+}7979+8080+static bool8181+xt_cluster_mt(const struct sk_buff *skb, const struct xt_match_param *par)8282+{8383+ struct sk_buff *pskb = (struct sk_buff *)skb;8484+ const struct xt_cluster_match_info *info = par->matchinfo;8585+ const struct nf_conn *ct;8686+ enum ip_conntrack_info ctinfo;8787+ unsigned long hash;8888+8989+ /* This match assumes that all nodes see the same packets. This can be9090+ * achieved if the switch that connects the cluster nodes support some9191+ * sort of 'port mirroring'. However, if your switch does not support9292+ * this, your cluster nodes can reply ARP request using a multicast MAC9393+ * address. Thus, your switch will flood the same packets to the9494+ * cluster nodes with the same multicast MAC address. Using a multicast9595+ * link address is a RFC 1812 (section 3.3.2) violation, but this works9696+ * fine in practise.9797+ *9898+ * Unfortunately, if you use the multicast MAC address, the link layer9999+ * sets skbuff's pkt_type to PACKET_MULTICAST, which is not accepted100100+ * by TCP and others for packets coming to this node. For that reason,101101+ * this match mangles skbuff's pkt_type if it detects a packet102102+ * addressed to a unicast address but using PACKET_MULTICAST. Yes, I103103+ * know, matches should not alter packets, but we are doing this here104104+ * because we would need to add a PKTTYPE target for this sole purpose.105105+ */106106+ if (!xt_cluster_is_multicast_addr(skb, par->family) &&107107+ skb->pkt_type == PACKET_MULTICAST) {108108+ pskb->pkt_type = PACKET_HOST;109109+ }110110+111111+ ct = nf_ct_get(skb, &ctinfo);112112+ if (ct == NULL)113113+ return false;114114+115115+ if (ct == &nf_conntrack_untracked)116116+ return false;117117+118118+ if (ct->master)119119+ hash = xt_cluster_hash(ct->master, info);120120+ else121121+ hash = xt_cluster_hash(ct, info);122122+123123+ return !!((1 << hash) & info->node_mask) ^124124+ !!(info->flags & XT_CLUSTER_F_INV);125125+}126126+127127+static bool xt_cluster_mt_checkentry(const struct xt_mtchk_param *par)128128+{129129+ struct xt_cluster_match_info *info = par->matchinfo;130130+131131+ if (info->node_mask >= (1 << info->total_nodes)) {132132+ printk(KERN_ERR "xt_cluster: this node mask cannot be "133133+ "higher than the total number of nodes\n");134134+ return false;135135+ }136136+ return true;137137+}138138+139139+static struct xt_match xt_cluster_match __read_mostly = {140140+ .name = "cluster",141141+ .family = NFPROTO_UNSPEC,142142+ .match = xt_cluster_mt,143143+ .checkentry = xt_cluster_mt_checkentry,144144+ .matchsize = sizeof(struct xt_cluster_match_info),145145+ .me = THIS_MODULE,146146+};147147+148148+static int __init xt_cluster_mt_init(void)149149+{150150+ return xt_register_match(&xt_cluster_match);151151+}152152+153153+static void __exit xt_cluster_mt_fini(void)154154+{155155+ xt_unregister_match(&xt_cluster_match);156156+}157157+158158+MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");159159+MODULE_LICENSE("GPL");160160+MODULE_DESCRIPTION("Xtables: hash-based cluster match");161161+MODULE_ALIAS("ipt_cluster");162162+MODULE_ALIAS("ip6t_cluster");163163+module_init(xt_cluster_mt_init);164164+module_exit(xt_cluster_mt_fini);
+2-5
net/netfilter/xt_hashlimit.c
···149149 /* initialize hash with random val at the time we allocate150150 * the first hashtable entry */151151 if (!ht->rnd_initialized) {152152- get_random_bytes(&ht->rnd, 4);152152+ get_random_bytes(&ht->rnd, sizeof(ht->rnd));153153 ht->rnd_initialized = 1;154154 }155155···565565static bool566566hashlimit_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)567567{568568- const struct xt_hashlimit_info *r =569569- ((const struct xt_hashlimit_info *)par->matchinfo)->u.master;568568+ const struct xt_hashlimit_info *r = par->matchinfo;570569 struct xt_hashlimit_htable *hinfo = r->hinfo;571570 unsigned long now = jiffies;572571 struct dsthash_ent *dh;···701702 }702703 mutex_unlock(&hlimit_mutex);703704704704- /* Ugly hack: For SMP, we only want to use one set */705705- r->u.master = r;706705 return true;707706}708707
+108
net/netfilter/xt_hl.c
···11+/*22+ * IP tables module for matching the value of the TTL33+ * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>44+ *55+ * Hop Limit matching module66+ * (C) 2001-2002 Maciej Soltysiak <solt@dns.toxicfilms.tv>77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+1313+#include <linux/ip.h>1414+#include <linux/ipv6.h>1515+#include <linux/module.h>1616+#include <linux/skbuff.h>1717+1818+#include <linux/netfilter/x_tables.h>1919+#include <linux/netfilter_ipv4/ipt_ttl.h>2020+#include <linux/netfilter_ipv6/ip6t_hl.h>2121+2222+MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");2323+MODULE_DESCRIPTION("Xtables: Hoplimit/TTL field match");2424+MODULE_LICENSE("GPL");2525+MODULE_ALIAS("ipt_ttl");2626+MODULE_ALIAS("ip6t_hl");2727+2828+static bool ttl_mt(const struct sk_buff *skb, const struct xt_match_param *par)2929+{3030+ const struct ipt_ttl_info *info = par->matchinfo;3131+ const u8 ttl = ip_hdr(skb)->ttl;3232+3333+ switch (info->mode) {3434+ case IPT_TTL_EQ:3535+ return ttl == info->ttl;3636+ case IPT_TTL_NE:3737+ return ttl != info->ttl;3838+ case IPT_TTL_LT:3939+ return ttl < info->ttl;4040+ case IPT_TTL_GT:4141+ return ttl > info->ttl;4242+ default:4343+ printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",4444+ info->mode);4545+ return false;4646+ }4747+4848+ return false;4949+}5050+5151+static bool hl_mt6(const struct sk_buff *skb, const struct xt_match_param *par)5252+{5353+ const struct ip6t_hl_info *info = par->matchinfo;5454+ const struct ipv6hdr *ip6h = ipv6_hdr(skb);5555+5656+ switch (info->mode) {5757+ case IP6T_HL_EQ:5858+ return ip6h->hop_limit == info->hop_limit;5959+ break;6060+ case IP6T_HL_NE:6161+ return ip6h->hop_limit != info->hop_limit;6262+ break;6363+ case IP6T_HL_LT:6464+ return ip6h->hop_limit < info->hop_limit;6565+ break;6666+ case IP6T_HL_GT:6767+ return ip6h->hop_limit > info->hop_limit;6868+ break;6969+ default:7070+ printk(KERN_WARNING "ip6t_hl: unknown mode %d\n",7171+ info->mode);7272+ return false;7373+ }7474+7575+ return false;7676+}7777+7878+static struct xt_match hl_mt_reg[] __read_mostly = {7979+ {8080+ .name = "ttl",8181+ .revision = 0,8282+ .family = NFPROTO_IPV4,8383+ .match = ttl_mt,8484+ .matchsize = sizeof(struct ipt_ttl_info),8585+ .me = THIS_MODULE,8686+ },8787+ {8888+ .name = "hl",8989+ .revision = 0,9090+ .family = NFPROTO_IPV6,9191+ .match = hl_mt6,9292+ .matchsize = sizeof(struct ip6t_hl_info),9393+ .me = THIS_MODULE,9494+ },9595+};9696+9797+static int __init hl_mt_init(void)9898+{9999+ return xt_register_matches(hl_mt_reg, ARRAY_SIZE(hl_mt_reg));100100+}101101+102102+static void __exit hl_mt_exit(void)103103+{104104+ xt_unregister_matches(hl_mt_reg, ARRAY_SIZE(hl_mt_reg));105105+}106106+107107+module_init(hl_mt_init);108108+module_exit(hl_mt_exit);
+29-11
net/netfilter/xt_limit.c
···1414#include <linux/netfilter/x_tables.h>1515#include <linux/netfilter/xt_limit.h>16161717+struct xt_limit_priv {1818+ unsigned long prev;1919+ uint32_t credit;2020+};2121+1722MODULE_LICENSE("GPL");1823MODULE_AUTHOR("Herve Eychenne <rv@wallfire.org>");1924MODULE_DESCRIPTION("Xtables: rate-limit match");···6560static bool6661limit_mt(const struct sk_buff *skb, const struct xt_match_param *par)6762{6868- struct xt_rateinfo *r =6969- ((const struct xt_rateinfo *)par->matchinfo)->master;6363+ const struct xt_rateinfo *r = par->matchinfo;6464+ struct xt_limit_priv *priv = r->master;7065 unsigned long now = jiffies;71667267 spin_lock_bh(&limit_lock);7373- r->credit += (now - xchg(&r->prev, now)) * CREDITS_PER_JIFFY;7474- if (r->credit > r->credit_cap)7575- r->credit = r->credit_cap;6868+ priv->credit += (now - xchg(&priv->prev, now)) * CREDITS_PER_JIFFY;6969+ if (priv->credit > r->credit_cap)7070+ priv->credit = r->credit_cap;76717777- if (r->credit >= r->cost) {7272+ if (priv->credit >= r->cost) {7873 /* We're not limited. */7979- r->credit -= r->cost;7474+ priv->credit -= r->cost;8075 spin_unlock_bh(&limit_lock);8176 return true;8277 }···10095static bool limit_mt_check(const struct xt_mtchk_param *par)10196{10297 struct xt_rateinfo *r = par->matchinfo;9898+ struct xt_limit_priv *priv;10399104100 /* Check for overflow. */105101 if (r->burst == 0···110104 return false;111105 }112106113113- /* For SMP, we only want to use one set of counters. */114114- r->master = r;107107+ priv = kmalloc(sizeof(*priv), GFP_KERNEL);108108+ if (priv == NULL)109109+ return -ENOMEM;110110+111111+ /* For SMP, we only want to use one set of state. */112112+ r->master = priv;115113 if (r->cost == 0) {116114 /* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies *117115 128. */118118- r->prev = jiffies;119119- r->credit = user2credits(r->avg * r->burst); /* Credits full. */116116+ priv->prev = jiffies;117117+ priv->credit = user2credits(r->avg * r->burst); /* Credits full. */120118 r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */121119 r->cost = user2credits(r->avg);122120 }123121 return true;122122+}123123+124124+static void limit_mt_destroy(const struct xt_mtdtor_param *par)125125+{126126+ const struct xt_rateinfo *info = par->matchinfo;127127+128128+ kfree(info->master);124129}125130126131#ifdef CONFIG_COMPAT···184167 .family = NFPROTO_UNSPEC,185168 .match = limit_mt,186169 .checkentry = limit_mt_check,170170+ .destroy = limit_mt_destroy,187171 .matchsize = sizeof(struct xt_rateinfo),188172#ifdef CONFIG_COMPAT189173 .compatsize = sizeof(struct compat_xt_rateinfo),
+23-14
net/netfilter/xt_physdev.c
···2020MODULE_ALIAS("ipt_physdev");2121MODULE_ALIAS("ip6t_physdev");22222323+static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask)2424+{2525+ const unsigned long *a = (const unsigned long *)_a;2626+ const unsigned long *b = (const unsigned long *)_b;2727+ const unsigned long *mask = (const unsigned long *)_mask;2828+ unsigned long ret;2929+3030+ ret = (a[0] ^ b[0]) & mask[0];3131+ if (IFNAMSIZ > sizeof(unsigned long))3232+ ret |= (a[1] ^ b[1]) & mask[1];3333+ if (IFNAMSIZ > 2 * sizeof(unsigned long))3434+ ret |= (a[2] ^ b[2]) & mask[2];3535+ if (IFNAMSIZ > 3 * sizeof(unsigned long))3636+ ret |= (a[3] ^ b[3]) & mask[3];3737+ BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));3838+ return ret;3939+}4040+2341static bool2442physdev_mt(const struct sk_buff *skb, const struct xt_match_param *par)2543{2626- int i;2727- static const char nulldevname[IFNAMSIZ];4444+ static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));2845 const struct xt_physdev_info *info = par->matchinfo;2929- bool ret;4646+ unsigned long ret;3047 const char *indev, *outdev;3148 const struct nf_bridge_info *nf_bridge;3249···8568 if (!(info->bitmask & XT_PHYSDEV_OP_IN))8669 goto match_outdev;8770 indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;8888- for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {8989- ret |= (((const unsigned int *)indev)[i]9090- ^ ((const unsigned int *)info->physindev)[i])9191- & ((const unsigned int *)info->in_mask)[i];9292- }7171+ ret = ifname_compare(indev, info->physindev, info->in_mask);93729473 if (!ret ^ !(info->invert & XT_PHYSDEV_OP_IN))9574 return false;···9582 return true;9683 outdev = nf_bridge->physoutdev ?9784 nf_bridge->physoutdev->name : nulldevname;9898- for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {9999- ret |= (((const unsigned int *)outdev)[i]100100- ^ ((const unsigned int *)info->physoutdev)[i])101101- & ((const unsigned int *)info->out_mask)[i];102102- }8585+ ret = ifname_compare(outdev, info->physoutdev, info->out_mask);10386104104- return ret ^ !(info->invert & XT_PHYSDEV_OP_OUT);8787+ return (!!ret ^ !(info->invert & XT_PHYSDEV_OP_OUT));10588}1068910790static bool physdev_mt_check(const struct xt_mtchk_param *par)
+24-7
net/netfilter/xt_quota.c
···99#include <linux/netfilter/x_tables.h>1010#include <linux/netfilter/xt_quota.h>11111212+struct xt_quota_priv {1313+ uint64_t quota;1414+};1515+1216MODULE_LICENSE("GPL");1317MODULE_AUTHOR("Sam Johnston <samj@samj.net>");1418MODULE_DESCRIPTION("Xtables: countdown quota match");···2420static bool2521quota_mt(const struct sk_buff *skb, const struct xt_match_param *par)2622{2727- struct xt_quota_info *q =2828- ((const struct xt_quota_info *)par->matchinfo)->master;2323+ struct xt_quota_info *q = (void *)par->matchinfo;2424+ struct xt_quota_priv *priv = q->master;2925 bool ret = q->flags & XT_QUOTA_INVERT;30263127 spin_lock_bh("a_lock);3232- if (q->quota >= skb->len) {3333- q->quota -= skb->len;2828+ if (priv->quota >= skb->len) {2929+ priv->quota -= skb->len;3430 ret = !ret;3531 } else {3632 /* we do not allow even small packets from now on */3737- q->quota = 0;3333+ priv->quota = 0;3834 }3535+ /* Copy quota back to matchinfo so that iptables can display it */3636+ q->quota = priv->quota;3937 spin_unlock_bh("a_lock);40384139 return ret;···49435044 if (q->flags & ~XT_QUOTA_MASK)5145 return false;5252- /* For SMP, we only want to use one set of counters. */5353- q->master = q;4646+4747+ q->master = kmalloc(sizeof(*q->master), GFP_KERNEL);4848+ if (q->master == NULL)4949+ return -ENOMEM;5050+5451 return true;5252+}5353+5454+static void quota_mt_destroy(const struct xt_mtdtor_param *par)5555+{5656+ const struct xt_quota_info *q = par->matchinfo;5757+5858+ kfree(q->master);5559}56605761static struct xt_match quota_mt_reg __read_mostly = {···7054 .family = NFPROTO_UNSPEC,7155 .match = quota_mt,7256 .checkentry = quota_mt_check,5757+ .destroy = quota_mt_destroy,7358 .matchsize = sizeof(struct xt_quota_info),7459 .me = THIS_MODULE,7560};
···1117111711181118 read_unlock(&nl_table_lock);11191119}11201120+EXPORT_SYMBOL(netlink_set_err);1120112111211122/* must be called with netlink table grabbed */11221123static void netlink_update_socket_mc(struct netlink_sock *nlk,
+1-1
net/sysctl_net.c
···6161static int net_ctl_ro_header_perms(struct ctl_table_root *root,6262 struct nsproxy *namespaces, struct ctl_table *table)6363{6464- if (namespaces->net_ns == &init_net)6464+ if (net_eq(namespaces->net_ns, &init_net))6565 return table->mode;6666 else6767 return table->mode & ~0222;