@@ -218,27 +218,26 @@ static inline int ip_vs_conn_unhash(struct ip_vs_conn *cp)
218218/*
219219 * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
220220 * Called for pkts coming from OUTside-to-INside.
221- * s_addr, s_port : pkt source address (foreign host)
222- * d_addr, d_port : pkt dest address (load balancer)
221+ * p->caddr, p->cport : pkt source address (foreign host)
222+ * p->vaddr, p->vport : pkt dest address (load balancer)
223223 */
224- static inline struct ip_vs_conn * __ip_vs_conn_in_get
225- (int af , int protocol , const union nf_inet_addr * s_addr , __be16 s_port ,
226- const union nf_inet_addr * d_addr , __be16 d_port )
224+ static inline struct ip_vs_conn *
225+ __ip_vs_conn_in_get (const struct ip_vs_conn_param * p )
227226{
228227 unsigned hash ;
229228 struct ip_vs_conn * cp ;
230229
231- hash = ip_vs_conn_hashkey (af , protocol , s_addr , s_port );
230+ hash = ip_vs_conn_hashkey (p -> af , p -> protocol , p -> caddr , p -> cport );
232231
233232 ct_read_lock (hash );
234233
235234 list_for_each_entry (cp , & ip_vs_conn_tab [hash ], c_list ) {
236- if (cp -> af == af &&
237- ip_vs_addr_equal (af , s_addr , & cp -> caddr ) &&
238- ip_vs_addr_equal (af , d_addr , & cp -> vaddr ) &&
239- s_port == cp -> cport && d_port == cp -> vport &&
240- ((!s_port ) ^ (!(cp -> flags & IP_VS_CONN_F_NO_CPORT ))) &&
241- protocol == cp -> protocol ) {
235+ if (cp -> af == p -> af &&
236+ ip_vs_addr_equal (p -> af , p -> caddr , & cp -> caddr ) &&
237+ ip_vs_addr_equal (p -> af , p -> vaddr , & cp -> vaddr ) &&
238+ p -> cport == cp -> cport && p -> vport == cp -> vport &&
239+ ((!p -> cport ) ^ (!(cp -> flags & IP_VS_CONN_F_NO_CPORT ))) &&
240+ p -> protocol == cp -> protocol ) {
242241 /* HIT */
243242 atomic_inc (& cp -> refcnt );
244243 ct_read_unlock (hash );
@@ -251,71 +250,82 @@ static inline struct ip_vs_conn *__ip_vs_conn_in_get
251250 return NULL ;
252251}
253252
254- struct ip_vs_conn * ip_vs_conn_in_get
255- (int af , int protocol , const union nf_inet_addr * s_addr , __be16 s_port ,
256- const union nf_inet_addr * d_addr , __be16 d_port )
253+ struct ip_vs_conn * ip_vs_conn_in_get (const struct ip_vs_conn_param * p )
257254{
258255 struct ip_vs_conn * cp ;
259256
260- cp = __ip_vs_conn_in_get (af , protocol , s_addr , s_port , d_addr , d_port );
261- if (!cp && atomic_read (& ip_vs_conn_no_cport_cnt ))
262- cp = __ip_vs_conn_in_get (af , protocol , s_addr , 0 , d_addr ,
263- d_port );
257+ cp = __ip_vs_conn_in_get (p );
258+ if (!cp && atomic_read (& ip_vs_conn_no_cport_cnt )) {
259+ struct ip_vs_conn_param cport_zero_p = * p ;
260+ cport_zero_p .cport = 0 ;
261+ cp = __ip_vs_conn_in_get (& cport_zero_p );
262+ }
264263
265264 IP_VS_DBG_BUF (9 , "lookup/in %s %s:%d->%s:%d %s\n" ,
266- ip_vs_proto_name (protocol ),
267- IP_VS_DBG_ADDR (af , s_addr ), ntohs (s_port ),
268- IP_VS_DBG_ADDR (af , d_addr ), ntohs (d_port ),
265+ ip_vs_proto_name (p -> protocol ),
266+ IP_VS_DBG_ADDR (p -> af , p -> caddr ), ntohs (p -> cport ),
267+ IP_VS_DBG_ADDR (p -> af , p -> vaddr ), ntohs (p -> vport ),
269268 cp ? "hit" : "not hit" );
270269
271270 return cp ;
272271}
273272
273+ static int
274+ ip_vs_conn_fill_param_proto (int af , const struct sk_buff * skb ,
275+ const struct ip_vs_iphdr * iph ,
276+ unsigned int proto_off , int inverse ,
277+ struct ip_vs_conn_param * p )
278+ {
279+ __be16 _ports [2 ], * pptr ;
280+
281+ pptr = skb_header_pointer (skb , proto_off , sizeof (_ports ), _ports );
282+ if (pptr == NULL )
283+ return 1 ;
284+
285+ if (likely (!inverse ))
286+ ip_vs_conn_fill_param (af , iph -> protocol , & iph -> saddr , pptr [0 ],
287+ & iph -> daddr , pptr [1 ], p );
288+ else
289+ ip_vs_conn_fill_param (af , iph -> protocol , & iph -> daddr , pptr [1 ],
290+ & iph -> saddr , pptr [0 ], p );
291+ return 0 ;
292+ }
293+
274294struct ip_vs_conn *
275295ip_vs_conn_in_get_proto (int af , const struct sk_buff * skb ,
276296 struct ip_vs_protocol * pp ,
277297 const struct ip_vs_iphdr * iph ,
278298 unsigned int proto_off , int inverse )
279299{
280- __be16 _ports [ 2 ], * pptr ;
300+ struct ip_vs_conn_param p ;
281301
282- pptr = skb_header_pointer (skb , proto_off , sizeof (_ports ), _ports );
283- if (pptr == NULL )
302+ if (ip_vs_conn_fill_param_proto (af , skb , iph , proto_off , inverse , & p ))
284303 return NULL ;
285304
286- if (likely (!inverse ))
287- return ip_vs_conn_in_get (af , iph -> protocol ,
288- & iph -> saddr , pptr [0 ],
289- & iph -> daddr , pptr [1 ]);
290- else
291- return ip_vs_conn_in_get (af , iph -> protocol ,
292- & iph -> daddr , pptr [1 ],
293- & iph -> saddr , pptr [0 ]);
305+ return ip_vs_conn_in_get (& p );
294306}
295307EXPORT_SYMBOL_GPL (ip_vs_conn_in_get_proto );
296308
297309/* Get reference to connection template */
298- struct ip_vs_conn * ip_vs_ct_in_get
299- (int af , int protocol , const union nf_inet_addr * s_addr , __be16 s_port ,
300- const union nf_inet_addr * d_addr , __be16 d_port )
310+ struct ip_vs_conn * ip_vs_ct_in_get (const struct ip_vs_conn_param * p )
301311{
302312 unsigned hash ;
303313 struct ip_vs_conn * cp ;
304314
305- hash = ip_vs_conn_hashkey (af , protocol , s_addr , s_port );
315+ hash = ip_vs_conn_hashkey (p -> af , p -> protocol , p -> caddr , p -> cport );
306316
307317 ct_read_lock (hash );
308318
309319 list_for_each_entry (cp , & ip_vs_conn_tab [hash ], c_list ) {
310- if (cp -> af == af &&
311- ip_vs_addr_equal (af , s_addr , & cp -> caddr ) &&
320+ if (cp -> af == p -> af &&
321+ ip_vs_addr_equal (p -> af , p -> caddr , & cp -> caddr ) &&
312322 /* protocol should only be IPPROTO_IP if
313- * d_addr is a fwmark */
314- ip_vs_addr_equal (protocol == IPPROTO_IP ? AF_UNSPEC : af ,
315- d_addr , & cp -> vaddr ) &&
316- s_port == cp -> cport && d_port == cp -> vport &&
323+ * p->vaddr is a fwmark */
324+ ip_vs_addr_equal (p -> protocol == IPPROTO_IP ? AF_UNSPEC :
325+ p -> af , p -> vaddr , & cp -> vaddr ) &&
326+ p -> cport == cp -> cport && p -> vport == cp -> vport &&
317327 cp -> flags & IP_VS_CONN_F_TEMPLATE &&
318- protocol == cp -> protocol ) {
328+ p -> protocol == cp -> protocol ) {
319329 /* HIT */
320330 atomic_inc (& cp -> refcnt );
321331 goto out ;
@@ -327,40 +337,36 @@ struct ip_vs_conn *ip_vs_ct_in_get
327337 ct_read_unlock (hash );
328338
329339 IP_VS_DBG_BUF (9 , "template lookup/in %s %s:%d->%s:%d %s\n" ,
330- ip_vs_proto_name (protocol ),
331- IP_VS_DBG_ADDR (af , s_addr ), ntohs (s_port ),
332- IP_VS_DBG_ADDR (af , d_addr ), ntohs (d_port ),
340+ ip_vs_proto_name (p -> protocol ),
341+ IP_VS_DBG_ADDR (p -> af , p -> caddr ), ntohs (p -> cport ),
342+ IP_VS_DBG_ADDR (p -> af , p -> vaddr ), ntohs (p -> vport ),
333343 cp ? "hit" : "not hit" );
334344
335345 return cp ;
336346}
337347
338- /*
339- * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
340- * Called for pkts coming from inside-to-OUTside.
341- * s_addr, s_port: pkt source address (inside host)
342- * d_addr, d_port: pkt dest address (foreign host)
343- */
344- struct ip_vs_conn * ip_vs_conn_out_get
345- (int af , int protocol , const union nf_inet_addr * s_addr , __be16 s_port ,
346- const union nf_inet_addr * d_addr , __be16 d_port )
348+ /* Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab.
349+ * Called for pkts coming from inside-to-OUTside.
350+ * p->caddr, p->cport: pkt source address (inside host)
351+ * p->vaddr, p->vport: pkt dest address (foreign host) */
352+ struct ip_vs_conn * ip_vs_conn_out_get (const struct ip_vs_conn_param * p )
347353{
348354 unsigned hash ;
349355 struct ip_vs_conn * cp , * ret = NULL ;
350356
351357 /*
352358 * Check for "full" addressed entries
353359 */
354- hash = ip_vs_conn_hashkey (af , protocol , d_addr , d_port );
360+ hash = ip_vs_conn_hashkey (p -> af , p -> protocol , p -> vaddr , p -> vport );
355361
356362 ct_read_lock (hash );
357363
358364 list_for_each_entry (cp , & ip_vs_conn_tab [hash ], c_list ) {
359- if (cp -> af == af &&
360- ip_vs_addr_equal (af , d_addr , & cp -> caddr ) &&
361- ip_vs_addr_equal (af , s_addr , & cp -> daddr ) &&
362- d_port == cp -> cport && s_port == cp -> dport &&
363- protocol == cp -> protocol ) {
365+ if (cp -> af == p -> af &&
366+ ip_vs_addr_equal (p -> af , p -> vaddr , & cp -> caddr ) &&
367+ ip_vs_addr_equal (p -> af , p -> caddr , & cp -> daddr ) &&
368+ p -> vport == cp -> cport && p -> cport == cp -> dport &&
369+ p -> protocol == cp -> protocol ) {
364370 /* HIT */
365371 atomic_inc (& cp -> refcnt );
366372 ret = cp ;
@@ -371,9 +377,9 @@ struct ip_vs_conn *ip_vs_conn_out_get
371377 ct_read_unlock (hash );
372378
373379 IP_VS_DBG_BUF (9 , "lookup/out %s %s:%d->%s:%d %s\n" ,
374- ip_vs_proto_name (protocol ),
375- IP_VS_DBG_ADDR (af , s_addr ), ntohs (s_port ),
376- IP_VS_DBG_ADDR (af , d_addr ), ntohs (d_port ),
380+ ip_vs_proto_name (p -> protocol ),
381+ IP_VS_DBG_ADDR (p -> af , p -> caddr ), ntohs (p -> cport ),
382+ IP_VS_DBG_ADDR (p -> af , p -> vaddr ), ntohs (p -> vport ),
377383 ret ? "hit" : "not hit" );
378384
379385 return ret ;
@@ -385,20 +391,12 @@ ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
385391 const struct ip_vs_iphdr * iph ,
386392 unsigned int proto_off , int inverse )
387393{
388- __be16 _ports [ 2 ], * pptr ;
394+ struct ip_vs_conn_param p ;
389395
390- pptr = skb_header_pointer (skb , proto_off , sizeof (_ports ), _ports );
391- if (pptr == NULL )
396+ if (ip_vs_conn_fill_param_proto (af , skb , iph , proto_off , inverse , & p ))
392397 return NULL ;
393398
394- if (likely (!inverse ))
395- return ip_vs_conn_out_get (af , iph -> protocol ,
396- & iph -> saddr , pptr [0 ],
397- & iph -> daddr , pptr [1 ]);
398- else
399- return ip_vs_conn_out_get (af , iph -> protocol ,
400- & iph -> daddr , pptr [1 ],
401- & iph -> saddr , pptr [0 ]);
399+ return ip_vs_conn_out_get (& p );
402400}
403401EXPORT_SYMBOL_GPL (ip_vs_conn_out_get_proto );
404402
@@ -758,13 +756,12 @@ void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
758756 * Create a new connection entry and hash it into the ip_vs_conn_tab
759757 */
760758struct ip_vs_conn *
761- ip_vs_conn_new (int af , int proto , const union nf_inet_addr * caddr , __be16 cport ,
762- const union nf_inet_addr * vaddr , __be16 vport ,
759+ ip_vs_conn_new (const struct ip_vs_conn_param * p ,
763760 const union nf_inet_addr * daddr , __be16 dport , unsigned flags ,
764761 struct ip_vs_dest * dest )
765762{
766763 struct ip_vs_conn * cp ;
767- struct ip_vs_protocol * pp = ip_vs_proto_get (proto );
764+ struct ip_vs_protocol * pp = ip_vs_proto_get (p -> protocol );
768765
769766 cp = kmem_cache_zalloc (ip_vs_conn_cachep , GFP_ATOMIC );
770767 if (cp == NULL ) {
@@ -774,14 +771,14 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
774771
775772 INIT_LIST_HEAD (& cp -> c_list );
776773 setup_timer (& cp -> timer , ip_vs_conn_expire , (unsigned long )cp );
777- cp -> af = af ;
778- cp -> protocol = proto ;
779- ip_vs_addr_copy (af , & cp -> caddr , caddr );
780- cp -> cport = cport ;
781- ip_vs_addr_copy (af , & cp -> vaddr , vaddr );
782- cp -> vport = vport ;
774+ cp -> af = p -> af ;
775+ cp -> protocol = p -> protocol ;
776+ ip_vs_addr_copy (p -> af , & cp -> caddr , p -> caddr );
777+ cp -> cport = p -> cport ;
778+ ip_vs_addr_copy (p -> af , & cp -> vaddr , p -> vaddr );
779+ cp -> vport = p -> vport ;
783780 /* proto should only be IPPROTO_IP if d_addr is a fwmark */
784- ip_vs_addr_copy (proto == IPPROTO_IP ? AF_UNSPEC : af ,
781+ ip_vs_addr_copy (p -> protocol == IPPROTO_IP ? AF_UNSPEC : p -> af ,
785782 & cp -> daddr , daddr );
786783 cp -> dport = dport ;
787784 cp -> flags = flags ;
@@ -810,7 +807,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
810807
811808 /* Bind its packet transmitter */
812809#ifdef CONFIG_IP_VS_IPV6
813- if (af == AF_INET6 )
810+ if (p -> af == AF_INET6 )
814811 ip_vs_bind_xmit_v6 (cp );
815812 else
816813#endif
0 commit comments