Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipvs: provide default ip_vs_conn_{in,out}_get_proto

This removes duplicate code by providing a default implementation
which is used by 3 of the 4 modules that provide these call.

Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Simon Horman and committed by
Patrick McHardy
5c0d2374 2890a157

+63 -153
+12
include/net/ip_vs.h
··· 632 632 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, 633 633 const union nf_inet_addr *d_addr, __be16 d_port); 634 634 635 + struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, 636 + struct ip_vs_protocol *pp, 637 + const struct ip_vs_iphdr *iph, 638 + unsigned int proto_off, 639 + int inverse); 640 + 635 641 extern struct ip_vs_conn *ip_vs_conn_out_get 636 642 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, 637 643 const union nf_inet_addr *d_addr, __be16 d_port); 644 + 645 + struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, 646 + struct ip_vs_protocol *pp, 647 + const struct ip_vs_iphdr *iph, 648 + unsigned int proto_off, 649 + int inverse); 638 650 639 651 /* put back the conn without restarting its timer */ 640 652 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
+45
net/netfilter/ipvs/ip_vs_conn.c
··· 271 271 return cp; 272 272 } 273 273 274 + struct ip_vs_conn * 275 + ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, 276 + struct ip_vs_protocol *pp, 277 + const struct ip_vs_iphdr *iph, 278 + unsigned int proto_off, int inverse) 279 + { 280 + __be16 _ports[2], *pptr; 281 + 282 + pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 283 + if (pptr == NULL) 284 + return NULL; 285 + 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]); 294 + } 295 + EXPORT_SYMBOL_GPL(ip_vs_conn_in_get_proto); 296 + 274 297 /* Get reference to connection template */ 275 298 struct ip_vs_conn *ip_vs_ct_in_get 276 299 (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, ··· 379 356 return ret; 380 357 } 381 358 359 + struct ip_vs_conn * 360 + ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, 361 + struct ip_vs_protocol *pp, 362 + const struct ip_vs_iphdr *iph, 363 + unsigned int proto_off, int inverse) 364 + { 365 + __be16 _ports[2], *pptr; 366 + 367 + pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 368 + if (pptr == NULL) 369 + return NULL; 370 + 371 + if (likely(!inverse)) 372 + return ip_vs_conn_out_get(af, iph->protocol, 373 + &iph->saddr, pptr[0], 374 + &iph->daddr, pptr[1]); 375 + else 376 + return ip_vs_conn_out_get(af, iph->protocol, 377 + &iph->daddr, pptr[1], 378 + &iph->saddr, pptr[0]); 379 + } 380 + EXPORT_SYMBOL_GPL(ip_vs_conn_out_get_proto); 382 381 383 382 /* 384 383 * Put back the conn and restart its timer with its timeout
+2 -51
net/netfilter/ipvs/ip_vs_proto_sctp.c
··· 8 8 #include <net/sctp/checksum.h> 9 9 #include <net/ip_vs.h> 10 10 11 - 12 - static struct ip_vs_conn * 13 - sctp_conn_in_get(int af, 14 - const struct sk_buff *skb, 15 - struct ip_vs_protocol *pp, 16 - const struct ip_vs_iphdr *iph, 17 - unsigned int proto_off, 18 - int inverse) 19 - { 20 - __be16 _ports[2], *pptr; 21 - 22 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 23 - if (pptr == NULL) 24 - return NULL; 25 - 26 - if (likely(!inverse)) 27 - return ip_vs_conn_in_get(af, iph->protocol, 28 - &iph->saddr, pptr[0], 29 - &iph->daddr, pptr[1]); 30 - else 31 - return ip_vs_conn_in_get(af, iph->protocol, 32 - &iph->daddr, pptr[1], 33 - &iph->saddr, pptr[0]); 34 - } 35 - 36 - static struct ip_vs_conn * 37 - sctp_conn_out_get(int af, 38 - const struct sk_buff *skb, 39 - struct ip_vs_protocol *pp, 40 - const struct ip_vs_iphdr *iph, 41 - unsigned int proto_off, 42 - int inverse) 43 - { 44 - __be16 _ports[2], *pptr; 45 - 46 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 47 - if (pptr == NULL) 48 - return NULL; 49 - 50 - if (likely(!inverse)) 51 - return ip_vs_conn_out_get(af, iph->protocol, 52 - &iph->saddr, pptr[0], 53 - &iph->daddr, pptr[1]); 54 - else 55 - return ip_vs_conn_out_get(af, iph->protocol, 56 - &iph->daddr, pptr[1], 57 - &iph->saddr, pptr[0]); 58 - } 59 - 60 11 static int 61 12 sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, 62 13 int *verdict, struct ip_vs_conn **cpp) ··· 1120 1169 .register_app = sctp_register_app, 1121 1170 .unregister_app = sctp_unregister_app, 1122 1171 .conn_schedule = sctp_conn_schedule, 1123 - .conn_in_get = sctp_conn_in_get, 1124 - .conn_out_get = sctp_conn_out_get, 1172 + .conn_in_get = ip_vs_conn_in_get_proto, 1173 + .conn_out_get = ip_vs_conn_out_get_proto, 1125 1174 .snat_handler = sctp_snat_handler, 1126 1175 .dnat_handler = sctp_dnat_handler, 1127 1176 .csum_check = sctp_csum_check,
+2 -48
net/netfilter/ipvs/ip_vs_proto_tcp.c
··· 27 27 28 28 #include <net/ip_vs.h> 29 29 30 - 31 - static struct ip_vs_conn * 32 - tcp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp, 33 - const struct ip_vs_iphdr *iph, unsigned int proto_off, 34 - int inverse) 35 - { 36 - __be16 _ports[2], *pptr; 37 - 38 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 39 - if (pptr == NULL) 40 - return NULL; 41 - 42 - if (likely(!inverse)) { 43 - return ip_vs_conn_in_get(af, iph->protocol, 44 - &iph->saddr, pptr[0], 45 - &iph->daddr, pptr[1]); 46 - } else { 47 - return ip_vs_conn_in_get(af, iph->protocol, 48 - &iph->daddr, pptr[1], 49 - &iph->saddr, pptr[0]); 50 - } 51 - } 52 - 53 - static struct ip_vs_conn * 54 - tcp_conn_out_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp, 55 - const struct ip_vs_iphdr *iph, unsigned int proto_off, 56 - int inverse) 57 - { 58 - __be16 _ports[2], *pptr; 59 - 60 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 61 - if (pptr == NULL) 62 - return NULL; 63 - 64 - if (likely(!inverse)) { 65 - return ip_vs_conn_out_get(af, iph->protocol, 66 - &iph->saddr, pptr[0], 67 - &iph->daddr, pptr[1]); 68 - } else { 69 - return ip_vs_conn_out_get(af, iph->protocol, 70 - &iph->daddr, pptr[1], 71 - &iph->saddr, pptr[0]); 72 - } 73 - } 74 - 75 - 76 30 static int 77 31 tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, 78 32 int *verdict, struct ip_vs_conn **cpp) ··· 675 721 .register_app = tcp_register_app, 676 722 .unregister_app = tcp_unregister_app, 677 723 .conn_schedule = tcp_conn_schedule, 678 - .conn_in_get = tcp_conn_in_get, 679 - .conn_out_get = tcp_conn_out_get, 724 + .conn_in_get = ip_vs_conn_in_get_proto, 725 + .conn_out_get = ip_vs_conn_out_get_proto, 680 726 .snat_handler = tcp_snat_handler, 681 727 .dnat_handler = tcp_dnat_handler, 682 728 .csum_check = tcp_csum_check,
+2 -54
net/netfilter/ipvs/ip_vs_proto_udp.c
··· 27 27 #include <net/ip.h> 28 28 #include <net/ip6_checksum.h> 29 29 30 - static struct ip_vs_conn * 31 - udp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp, 32 - const struct ip_vs_iphdr *iph, unsigned int proto_off, 33 - int inverse) 34 - { 35 - struct ip_vs_conn *cp; 36 - __be16 _ports[2], *pptr; 37 - 38 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 39 - if (pptr == NULL) 40 - return NULL; 41 - 42 - if (likely(!inverse)) { 43 - cp = ip_vs_conn_in_get(af, iph->protocol, 44 - &iph->saddr, pptr[0], 45 - &iph->daddr, pptr[1]); 46 - } else { 47 - cp = ip_vs_conn_in_get(af, iph->protocol, 48 - &iph->daddr, pptr[1], 49 - &iph->saddr, pptr[0]); 50 - } 51 - 52 - return cp; 53 - } 54 - 55 - 56 - static struct ip_vs_conn * 57 - udp_conn_out_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp, 58 - const struct ip_vs_iphdr *iph, unsigned int proto_off, 59 - int inverse) 60 - { 61 - struct ip_vs_conn *cp; 62 - __be16 _ports[2], *pptr; 63 - 64 - pptr = skb_header_pointer(skb, proto_off, sizeof(_ports), _ports); 65 - if (pptr == NULL) 66 - return NULL; 67 - 68 - if (likely(!inverse)) { 69 - cp = ip_vs_conn_out_get(af, iph->protocol, 70 - &iph->saddr, pptr[0], 71 - &iph->daddr, pptr[1]); 72 - } else { 73 - cp = ip_vs_conn_out_get(af, iph->protocol, 74 - &iph->daddr, pptr[1], 75 - &iph->saddr, pptr[0]); 76 - } 77 - 78 - return cp; 79 - } 80 - 81 - 82 30 static int 83 31 udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, 84 32 int *verdict, struct ip_vs_conn **cpp) ··· 468 520 .init = udp_init, 469 521 .exit = udp_exit, 470 522 .conn_schedule = udp_conn_schedule, 471 - .conn_in_get = udp_conn_in_get, 472 - .conn_out_get = udp_conn_out_get, 523 + .conn_in_get = ip_vs_conn_in_get_proto, 524 + .conn_out_get = ip_vs_conn_out_get_proto, 473 525 .snat_handler = udp_snat_handler, 474 526 .dnat_handler = udp_dnat_handler, 475 527 .csum_check = udp_csum_check,