@@ -77,52 +77,6 @@ __ipq_enqueue_entry(struct ipq_queue_entry *entry)
77
77
queue_total ++ ;
78
78
}
79
79
80
- /*
81
- * Find and return a queued entry matched by cmpfn, or return the last
82
- * entry if cmpfn is NULL.
83
- */
84
- static inline struct ipq_queue_entry *
85
- __ipq_find_entry (ipq_cmpfn cmpfn , unsigned long data )
86
- {
87
- struct ipq_queue_entry * entry ;
88
-
89
- list_for_each_entry (entry , & queue_list , list ) {
90
- if (!cmpfn || cmpfn (entry , data ))
91
- return entry ;
92
- }
93
- return NULL ;
94
- }
95
-
96
- static inline void
97
- __ipq_dequeue_entry (struct ipq_queue_entry * entry )
98
- {
99
- list_del (& entry -> list );
100
- queue_total -- ;
101
- }
102
-
103
- static inline struct ipq_queue_entry *
104
- __ipq_find_dequeue_entry (ipq_cmpfn cmpfn , unsigned long data )
105
- {
106
- struct ipq_queue_entry * entry ;
107
-
108
- entry = __ipq_find_entry (cmpfn , data );
109
- if (entry == NULL )
110
- return NULL ;
111
-
112
- __ipq_dequeue_entry (entry );
113
- return entry ;
114
- }
115
-
116
-
117
- static inline void
118
- __ipq_flush (int verdict )
119
- {
120
- struct ipq_queue_entry * entry ;
121
-
122
- while ((entry = __ipq_find_dequeue_entry (NULL , 0 )))
123
- ipq_issue_verdict (entry , verdict );
124
- }
125
-
126
80
static inline int
127
81
__ipq_set_mode (unsigned char mode , unsigned int range )
128
82
{
@@ -149,31 +103,59 @@ __ipq_set_mode(unsigned char mode, unsigned int range)
149
103
return status ;
150
104
}
151
105
106
+ static void __ipq_flush (ipq_cmpfn cmpfn , unsigned long data );
107
+
152
108
static inline void
153
109
__ipq_reset (void )
154
110
{
155
111
peer_pid = 0 ;
156
112
net_disable_timestamp ();
157
113
__ipq_set_mode (IPQ_COPY_NONE , 0 );
158
- __ipq_flush (NF_DROP );
114
+ __ipq_flush (NULL , 0 );
159
115
}
160
116
161
117
static struct ipq_queue_entry *
162
- ipq_find_dequeue_entry (ipq_cmpfn cmpfn , unsigned long data )
118
+ ipq_find_dequeue_entry (unsigned long id )
163
119
{
164
- struct ipq_queue_entry * entry ;
120
+ struct ipq_queue_entry * entry = NULL , * i ;
165
121
166
122
write_lock_bh (& queue_lock );
167
- entry = __ipq_find_dequeue_entry (cmpfn , data );
123
+
124
+ list_for_each_entry (i , & queue_list , list ) {
125
+ if ((unsigned long )i == id ) {
126
+ entry = i ;
127
+ break ;
128
+ }
129
+ }
130
+
131
+ if (entry ) {
132
+ list_del (& entry -> list );
133
+ queue_total -- ;
134
+ }
135
+
168
136
write_unlock_bh (& queue_lock );
169
137
return entry ;
170
138
}
171
139
172
140
static void
173
- ipq_flush (int verdict )
141
+ __ipq_flush (ipq_cmpfn cmpfn , unsigned long data )
142
+ {
143
+ struct ipq_queue_entry * entry , * next ;
144
+
145
+ list_for_each_entry_safe (entry , next , & queue_list , list ) {
146
+ if (!cmpfn || cmpfn (entry , data )) {
147
+ list_del (& entry -> list );
148
+ queue_total -- ;
149
+ ipq_issue_verdict (entry , NF_DROP );
150
+ }
151
+ }
152
+ }
153
+
154
+ static void
155
+ ipq_flush (ipq_cmpfn cmpfn , unsigned long data )
174
156
{
175
157
write_lock_bh (& queue_lock );
176
- __ipq_flush (verdict );
158
+ __ipq_flush (cmpfn , data );
177
159
write_unlock_bh (& queue_lock );
178
160
}
179
161
@@ -367,12 +349,6 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct ipq_queue_entry *e)
367
349
return 0 ;
368
350
}
369
351
370
- static inline int
371
- id_cmp (struct ipq_queue_entry * e , unsigned long id )
372
- {
373
- return (id == (unsigned long )e );
374
- }
375
-
376
352
static int
377
353
ipq_set_verdict (struct ipq_verdict_msg * vmsg , unsigned int len )
378
354
{
@@ -381,7 +357,7 @@ ipq_set_verdict(struct ipq_verdict_msg *vmsg, unsigned int len)
381
357
if (vmsg -> value > NF_MAX_VERDICT )
382
358
return - EINVAL ;
383
359
384
- entry = ipq_find_dequeue_entry (id_cmp , vmsg -> id );
360
+ entry = ipq_find_dequeue_entry (vmsg -> id );
385
361
if (entry == NULL )
386
362
return - ENOENT ;
387
363
else {
@@ -460,10 +436,7 @@ dev_cmp(struct ipq_queue_entry *entry, unsigned long ifindex)
460
436
static void
461
437
ipq_dev_drop (int ifindex )
462
438
{
463
- struct ipq_queue_entry * entry ;
464
-
465
- while ((entry = ipq_find_dequeue_entry (dev_cmp , ifindex )) != NULL )
466
- ipq_issue_verdict (entry , NF_DROP );
439
+ ipq_flush (dev_cmp , ifindex );
467
440
}
468
441
469
442
#define RCV_SKB_FAIL (err ) do { netlink_ack(skb, nlh, (err)); return; } while (0)
@@ -699,7 +672,7 @@ static void __exit ip_queue_fini(void)
699
672
{
700
673
nf_unregister_queue_handlers (& nfqh );
701
674
synchronize_net ();
702
- ipq_flush (NF_DROP );
675
+ ipq_flush (NULL , 0 );
703
676
704
677
unregister_sysctl_table (ipq_sysctl_header );
705
678
unregister_netdevice_notifier (& ipq_dev_notifier );
0 commit comments