@@ -1025,43 +1025,42 @@ ip_vs_forward_icmp(unsigned int hooknum, struct sk_buff *skb,
10251025}
10261026
10271027
1028- /* After packet filtering, forward packet through VS/DR, VS/TUN,
1029- or VS/NAT(change destination), so that filtering rules can be
1030- applied to IPVS. */
1031- static struct nf_hook_ops ip_vs_in_ops = {
1032- .hook = ip_vs_in ,
1033- .owner = THIS_MODULE ,
1034- .pf = PF_INET ,
1035- .hooknum = NF_INET_LOCAL_IN ,
1036- .priority = 100 ,
1037- };
1038-
1039- /* After packet filtering, change source only for VS/NAT */
1040- static struct nf_hook_ops ip_vs_out_ops = {
1041- .hook = ip_vs_out ,
1042- .owner = THIS_MODULE ,
1043- .pf = PF_INET ,
1044- .hooknum = NF_INET_FORWARD ,
1045- .priority = 100 ,
1046- };
1047-
1048- /* After packet filtering (but before ip_vs_out_icmp), catch icmp
1049- destined for 0.0.0.0/0, which is for incoming IPVS connections */
1050- static struct nf_hook_ops ip_vs_forward_icmp_ops = {
1051- .hook = ip_vs_forward_icmp ,
1052- .owner = THIS_MODULE ,
1053- .pf = PF_INET ,
1054- .hooknum = NF_INET_FORWARD ,
1055- .priority = 99 ,
1056- };
1057-
1058- /* Before the netfilter connection tracking, exit from POST_ROUTING */
1059- static struct nf_hook_ops ip_vs_post_routing_ops = {
1060- .hook = ip_vs_post_routing ,
1061- .owner = THIS_MODULE ,
1062- .pf = PF_INET ,
1063- .hooknum = NF_INET_POST_ROUTING ,
1064- .priority = NF_IP_PRI_NAT_SRC - 1 ,
1028+ static struct nf_hook_ops ip_vs_ops [] = {
1029+ /* After packet filtering, forward packet through VS/DR, VS/TUN,
1030+ * or VS/NAT(change destination), so that filtering rules can be
1031+ * applied to IPVS. */
1032+ {
1033+ .hook = ip_vs_in ,
1034+ .owner = THIS_MODULE ,
1035+ .pf = PF_INET ,
1036+ .hooknum = NF_INET_LOCAL_IN ,
1037+ .priority = 100 ,
1038+ },
1039+ /* After packet filtering, change source only for VS/NAT */
1040+ {
1041+ .hook = ip_vs_out ,
1042+ .owner = THIS_MODULE ,
1043+ .pf = PF_INET ,
1044+ .hooknum = NF_INET_FORWARD ,
1045+ .priority = 100 ,
1046+ },
1047+ /* After packet filtering (but before ip_vs_out_icmp), catch icmp
1048+ * destined for 0.0.0.0/0, which is for incoming IPVS connections */
1049+ {
1050+ .hook = ip_vs_forward_icmp ,
1051+ .owner = THIS_MODULE ,
1052+ .pf = PF_INET ,
1053+ .hooknum = NF_INET_FORWARD ,
1054+ .priority = 99 ,
1055+ },
1056+ /* Before the netfilter connection tracking, exit from POST_ROUTING */
1057+ {
1058+ .hook = ip_vs_post_routing ,
1059+ .owner = THIS_MODULE ,
1060+ .pf = PF_INET ,
1061+ .hooknum = NF_INET_POST_ROUTING ,
1062+ .priority = NF_IP_PRI_NAT_SRC - 1 ,
1063+ },
10651064};
10661065
10671066
@@ -1092,37 +1091,15 @@ static int __init ip_vs_init(void)
10921091 goto cleanup_app ;
10931092 }
10941093
1095- ret = nf_register_hook ( & ip_vs_in_ops );
1094+ ret = nf_register_hooks ( ip_vs_ops , ARRAY_SIZE ( ip_vs_ops ) );
10961095 if (ret < 0 ) {
1097- IP_VS_ERR ("can't register in hook .\n" );
1096+ IP_VS_ERR ("can't register hooks .\n" );
10981097 goto cleanup_conn ;
10991098 }
11001099
1101- ret = nf_register_hook (& ip_vs_out_ops );
1102- if (ret < 0 ) {
1103- IP_VS_ERR ("can't register out hook.\n" );
1104- goto cleanup_inops ;
1105- }
1106- ret = nf_register_hook (& ip_vs_post_routing_ops );
1107- if (ret < 0 ) {
1108- IP_VS_ERR ("can't register post_routing hook.\n" );
1109- goto cleanup_outops ;
1110- }
1111- ret = nf_register_hook (& ip_vs_forward_icmp_ops );
1112- if (ret < 0 ) {
1113- IP_VS_ERR ("can't register forward_icmp hook.\n" );
1114- goto cleanup_postroutingops ;
1115- }
1116-
11171100 IP_VS_INFO ("ipvs loaded.\n" );
11181101 return ret ;
11191102
1120- cleanup_postroutingops :
1121- nf_unregister_hook (& ip_vs_post_routing_ops );
1122- cleanup_outops :
1123- nf_unregister_hook (& ip_vs_out_ops );
1124- cleanup_inops :
1125- nf_unregister_hook (& ip_vs_in_ops );
11261103 cleanup_conn :
11271104 ip_vs_conn_cleanup ();
11281105 cleanup_app :
@@ -1136,10 +1113,7 @@ static int __init ip_vs_init(void)
11361113
11371114static void __exit ip_vs_cleanup (void )
11381115{
1139- nf_unregister_hook (& ip_vs_forward_icmp_ops );
1140- nf_unregister_hook (& ip_vs_post_routing_ops );
1141- nf_unregister_hook (& ip_vs_out_ops );
1142- nf_unregister_hook (& ip_vs_in_ops );
1116+ nf_unregister_hooks (ip_vs_ops , ARRAY_SIZE (ip_vs_ops ));
11431117 ip_vs_conn_cleanup ();
11441118 ip_vs_app_cleanup ();
11451119 ip_vs_protocol_cleanup ();
0 commit comments