···11#ifndef _IP_CONNTRACK_CORE_H22#define _IP_CONNTRACK_CORE_H33#include <linux/netfilter.h>44-#include <linux/netfilter_ipv4/lockhelp.h>5465/* This header is used to share core functionality between the76 standalone connection tracking module, and the compatibility layer's use···46474748extern struct list_head *ip_conntrack_hash;4849extern struct list_head ip_conntrack_expect_list;4949-DECLARE_RWLOCK_EXTERN(ip_conntrack_lock);5050+extern rwlock_t ip_conntrack_lock;5051#endif /* _IP_CONNTRACK_CORE_H */5152
+1-2
include/linux/netfilter_ipv4/ip_nat.h
···50505151#ifdef __KERNEL__5252#include <linux/list.h>5353-#include <linux/netfilter_ipv4/lockhelp.h>54535554/* Protects NAT hash tables, and NAT-private part of conntracks. */5656-DECLARE_RWLOCK_EXTERN(ip_nat_lock);5555+extern rwlock_t ip_nat_lock;57565857/* The structure embedded in the conntrack structure. */5958struct ip_nat_info
-1
include/linux/netfilter_ipv4/listhelp.h
···22#define _LISTHELP_H33#include <linux/config.h>44#include <linux/list.h>55-#include <linux/netfilter_ipv4/lockhelp.h>6576/* Header to do more comprehensive job than linux/list.h; assume list87 is first entry in structure. */
···3636#include <linux/netfilter_ipv4.h>3737#include <linux/netfilter_ipv4/ip_conntrack.h>3838#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>3939-#include <linux/netfilter_ipv4/lockhelp.h>40394140#if 04241#define DEBUGP printk···4546#endif46474748/* Protects conntrack->proto.tcp */4848-static DECLARE_RWLOCK(tcp_lock);4949+static DEFINE_RWLOCK(tcp_lock);49505051/* "Be conservative in what you do, 5152 be liberal in what you accept from others." ···329330{330331 enum tcp_conntrack state;331332332332- READ_LOCK(&tcp_lock);333333+ read_lock_bh(&tcp_lock);333334 state = conntrack->proto.tcp.state;334334- READ_UNLOCK(&tcp_lock);335335+ read_unlock_bh(&tcp_lock);335336336337 return seq_printf(s, "%s ", tcp_conntrack_names[state]);337338}···737738738739 end = segment_seq_plus_len(ntohl(tcph->seq), skb->len, iph, tcph);739740740740- WRITE_LOCK(&tcp_lock);741741+ write_lock_bh(&tcp_lock);741742 /*742743 * We have to worry for the ack in the reply packet only...743744 */744745 if (after(end, conntrack->proto.tcp.seen[dir].td_end))745746 conntrack->proto.tcp.seen[dir].td_end = end;746747 conntrack->proto.tcp.last_end = end;747747- WRITE_UNLOCK(&tcp_lock);748748+ write_unlock_bh(&tcp_lock);748749 DEBUGP("tcp_update: sender end=%u maxend=%u maxwin=%u scale=%i "749750 "receiver end=%u maxend=%u maxwin=%u scale=%i\n",750751 sender->td_end, sender->td_maxend, sender->td_maxwin,···856857 sizeof(_tcph), &_tcph);857858 BUG_ON(th == NULL);858859859859- WRITE_LOCK(&tcp_lock);860860+ write_lock_bh(&tcp_lock);860861 old_state = conntrack->proto.tcp.state;861862 dir = CTINFO2DIR(ctinfo);862863 index = get_conntrack_index(th);···878879 * that the client cannot but retransmit its SYN and 879880 * thus initiate a clean new session.880881 */881881- WRITE_UNLOCK(&tcp_lock);882882+ write_unlock_bh(&tcp_lock);882883 if (LOG_INVALID(IPPROTO_TCP))883884 nf_log_packet(PF_INET, 0, skb, NULL, NULL, 884885 "ip_ct_tcp: killing out of sync session ");···893894 conntrack->proto.tcp.last_end = 894895 segment_seq_plus_len(ntohl(th->seq), skb->len, iph, th);895896896896- WRITE_UNLOCK(&tcp_lock);897897+ write_unlock_bh(&tcp_lock);897898 if (LOG_INVALID(IPPROTO_TCP))898899 nf_log_packet(PF_INET, 0, skb, NULL, NULL, 899900 "ip_ct_tcp: invalid packet ignored ");···903904 DEBUGP("ip_ct_tcp: Invalid dir=%i index=%u ostate=%u\n",904905 dir, get_conntrack_index(th),905906 old_state);906906- WRITE_UNLOCK(&tcp_lock);907907+ write_unlock_bh(&tcp_lock);907908 if (LOG_INVALID(IPPROTO_TCP))908909 nf_log_packet(PF_INET, 0, skb, NULL, NULL, 909910 "ip_ct_tcp: invalid state ");···917918 conntrack->proto.tcp.seen[dir].td_end)) { 918919 /* Attempt to reopen a closed connection.919920 * Delete this connection and look up again. */920920- WRITE_UNLOCK(&tcp_lock);921921+ write_unlock_bh(&tcp_lock);921922 if (del_timer(&conntrack->timeout))922923 conntrack->timeout.function((unsigned long)923924 conntrack);924925 return -NF_REPEAT;925926 } else {926926- WRITE_UNLOCK(&tcp_lock);927927+ write_unlock_bh(&tcp_lock);927928 if (LOG_INVALID(IPPROTO_TCP))928929 nf_log_packet(PF_INET, 0, skb, NULL, NULL,929930 "ip_ct_tcp: invalid SYN");···948949949950 if (!tcp_in_window(&conntrack->proto.tcp, dir, index, 950951 skb, iph, th)) {951951- WRITE_UNLOCK(&tcp_lock);952952+ write_unlock_bh(&tcp_lock);952953 return -NF_ACCEPT;953954 }954955 in_window:···971972 timeout = conntrack->proto.tcp.retrans >= ip_ct_tcp_max_retrans972973 && *tcp_timeouts[new_state] > ip_ct_tcp_timeout_max_retrans973974 ? ip_ct_tcp_timeout_max_retrans : *tcp_timeouts[new_state];974974- WRITE_UNLOCK(&tcp_lock);975975+ write_unlock_bh(&tcp_lock);975976976977 if (!test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)) {977978 /* If only reply is a RST, we can consider ourselves not to
+11-11
net/ipv4/netfilter/ip_conntrack_standalone.c
···2828#include <net/checksum.h>2929#include <net/ip.h>30303131-#define ASSERT_READ_LOCK(x) MUST_BE_READ_LOCKED(&ip_conntrack_lock)3232-#define ASSERT_WRITE_LOCK(x) MUST_BE_WRITE_LOCKED(&ip_conntrack_lock)3131+#define ASSERT_READ_LOCK(x)3232+#define ASSERT_WRITE_LOCK(x)33333434#include <linux/netfilter_ipv4/ip_conntrack.h>3535#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>···119119120120static void *ct_seq_start(struct seq_file *seq, loff_t *pos)121121{122122- READ_LOCK(&ip_conntrack_lock);122122+ read_lock_bh(&ip_conntrack_lock);123123 return ct_get_idx(seq, *pos);124124}125125···131131132132static void ct_seq_stop(struct seq_file *s, void *v)133133{134134- READ_UNLOCK(&ip_conntrack_lock);134134+ read_unlock_bh(&ip_conntrack_lock);135135}136136137137static int ct_seq_show(struct seq_file *s, void *v)···140140 const struct ip_conntrack *conntrack = tuplehash_to_ctrack(hash);141141 struct ip_conntrack_protocol *proto;142142143143- MUST_BE_READ_LOCKED(&ip_conntrack_lock);143143+ ASSERT_READ_LOCK(&ip_conntrack_lock);144144 IP_NF_ASSERT(conntrack);145145146146 /* we only want to print DIR_ORIGINAL */···239239240240 /* strange seq_file api calls stop even if we fail,241241 * thus we need to grab lock since stop unlocks */242242- READ_LOCK(&ip_conntrack_lock);242242+ read_lock_bh(&ip_conntrack_lock);243243244244 if (list_empty(e))245245 return NULL;···267267268268static void exp_seq_stop(struct seq_file *s, void *v)269269{270270- READ_UNLOCK(&ip_conntrack_lock);270270+ read_unlock_bh(&ip_conntrack_lock);271271}272272273273static int exp_seq_show(struct seq_file *s, void *v)···921921{922922 int ret = 0;923923924924- WRITE_LOCK(&ip_conntrack_lock);924924+ write_lock_bh(&ip_conntrack_lock);925925 if (ip_ct_protos[proto->proto] != &ip_conntrack_generic_protocol) {926926 ret = -EBUSY;927927 goto out;928928 }929929 ip_ct_protos[proto->proto] = proto;930930 out:931931- WRITE_UNLOCK(&ip_conntrack_lock);931931+ write_unlock_bh(&ip_conntrack_lock);932932 return ret;933933}934934935935void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)936936{937937- WRITE_LOCK(&ip_conntrack_lock);937937+ write_lock_bh(&ip_conntrack_lock);938938 ip_ct_protos[proto->proto] = &ip_conntrack_generic_protocol;939939- WRITE_UNLOCK(&ip_conntrack_lock);939939+ write_unlock_bh(&ip_conntrack_lock);940940941941 /* Somebody could be still looking at the proto in bh. */942942 synchronize_net();
+16-16
net/ipv4/netfilter/ip_nat_core.c
···2222#include <linux/udp.h>2323#include <linux/jhash.h>24242525-#define ASSERT_READ_LOCK(x) MUST_BE_READ_LOCKED(&ip_nat_lock)2626-#define ASSERT_WRITE_LOCK(x) MUST_BE_WRITE_LOCKED(&ip_nat_lock)2525+#define ASSERT_READ_LOCK(x)2626+#define ASSERT_WRITE_LOCK(x)27272828#include <linux/netfilter_ipv4/ip_conntrack.h>2929#include <linux/netfilter_ipv4/ip_conntrack_core.h>···4141#define DEBUGP(format, args...)4242#endif43434444-DECLARE_RWLOCK(ip_nat_lock);4444+DEFINE_RWLOCK(ip_nat_lock);45454646/* Calculated at init based on memory size */4747static unsigned int ip_nat_htable_size;···6565 if (!(conn->status & IPS_NAT_DONE_MASK))6666 return;67676868- WRITE_LOCK(&ip_nat_lock);6868+ write_lock_bh(&ip_nat_lock);6969 list_del(&conn->nat.info.bysource);7070- WRITE_UNLOCK(&ip_nat_lock);7070+ write_unlock_bh(&ip_nat_lock);7171}72727373/* We do checksum mangling, so if they were wrong before they're still···142142 unsigned int h = hash_by_src(tuple);143143 struct ip_conntrack *ct;144144145145- READ_LOCK(&ip_nat_lock);145145+ read_lock_bh(&ip_nat_lock);146146 list_for_each_entry(ct, &bysource[h], nat.info.bysource) {147147 if (same_src(ct, tuple)) {148148 /* Copy source part from reply tuple. */···151151 result->dst = tuple->dst;152152153153 if (in_range(result, range)) {154154- READ_UNLOCK(&ip_nat_lock);154154+ read_unlock_bh(&ip_nat_lock);155155 return 1;156156 }157157 }158158 }159159- READ_UNLOCK(&ip_nat_lock);159159+ read_unlock_bh(&ip_nat_lock);160160 return 0;161161}162162···297297 unsigned int srchash298298 = hash_by_src(&conntrack->tuplehash[IP_CT_DIR_ORIGINAL]299299 .tuple);300300- WRITE_LOCK(&ip_nat_lock);300300+ write_lock_bh(&ip_nat_lock);301301 list_add(&info->bysource, &bysource[srchash]);302302- WRITE_UNLOCK(&ip_nat_lock);302302+ write_unlock_bh(&ip_nat_lock);303303 }304304305305 /* It's done. */···474474{475475 int ret = 0;476476477477- WRITE_LOCK(&ip_nat_lock);477477+ write_lock_bh(&ip_nat_lock);478478 if (ip_nat_protos[proto->protonum] != &ip_nat_unknown_protocol) {479479 ret = -EBUSY;480480 goto out;481481 }482482 ip_nat_protos[proto->protonum] = proto;483483 out:484484- WRITE_UNLOCK(&ip_nat_lock);484484+ write_unlock_bh(&ip_nat_lock);485485 return ret;486486}487487488488/* Noone stores the protocol anywhere; simply delete it. */489489void ip_nat_protocol_unregister(struct ip_nat_protocol *proto)490490{491491- WRITE_LOCK(&ip_nat_lock);491491+ write_lock_bh(&ip_nat_lock);492492 ip_nat_protos[proto->protonum] = &ip_nat_unknown_protocol;493493- WRITE_UNLOCK(&ip_nat_lock);493493+ write_unlock_bh(&ip_nat_lock);494494495495 /* Someone could be still looking at the proto in a bh. */496496 synchronize_net();···509509 return -ENOMEM;510510511511 /* Sew in builtin protocols. */512512- WRITE_LOCK(&ip_nat_lock);512512+ write_lock_bh(&ip_nat_lock);513513 for (i = 0; i < MAX_IP_NAT_PROTO; i++)514514 ip_nat_protos[i] = &ip_nat_unknown_protocol;515515 ip_nat_protos[IPPROTO_TCP] = &ip_nat_protocol_tcp;516516 ip_nat_protos[IPPROTO_UDP] = &ip_nat_protocol_udp;517517 ip_nat_protos[IPPROTO_ICMP] = &ip_nat_protocol_icmp;518518- WRITE_UNLOCK(&ip_nat_lock);518518+ write_unlock_bh(&ip_nat_lock);519519520520 for (i = 0; i < ip_nat_htable_size; i++) {521521 INIT_LIST_HEAD(&bysource[i]);
+5-5
net/ipv4/netfilter/ip_nat_helper.c
···2828#include <net/tcp.h>2929#include <net/udp.h>30303131-#define ASSERT_READ_LOCK(x) MUST_BE_READ_LOCKED(&ip_nat_lock)3232-#define ASSERT_WRITE_LOCK(x) MUST_BE_WRITE_LOCKED(&ip_nat_lock)3131+#define ASSERT_READ_LOCK(x)3232+#define ASSERT_WRITE_LOCK(x)33333434#include <linux/netfilter_ipv4/ip_conntrack.h>3535#include <linux/netfilter_ipv4/ip_conntrack_helper.h>···4747#define DUMP_OFFSET(x)4848#endif49495050-static DECLARE_LOCK(ip_nat_seqofs_lock);5050+static DEFINE_SPINLOCK(ip_nat_seqofs_lock);51515252/* Setup TCP sequence correction given this change at this sequence */5353static inline void ···7070 DEBUGP("ip_nat_resize_packet: Seq_offset before: ");7171 DUMP_OFFSET(this_way);72727373- LOCK_BH(&ip_nat_seqofs_lock);7373+ spin_lock_bh(&ip_nat_seqofs_lock);74747575 /* SYN adjust. If it's uninitialized, or this is after last7676 * correction, record it: we don't handle more than one···8282 this_way->offset_before = this_way->offset_after;8383 this_way->offset_after += sizediff;8484 }8585- UNLOCK_BH(&ip_nat_seqofs_lock);8585+ spin_unlock_bh(&ip_nat_seqofs_lock);86868787 DEBUGP("ip_nat_resize_packet: Seq_offset after: ");8888 DUMP_OFFSET(this_way);