@@ -32,6 +32,7 @@ func Test_getProxyMode(t *testing.T) {
32
32
iptablesVersion string
33
33
ipsetVersion string
34
34
kmods []string
35
+ kernelVersion string
35
36
kernelCompat bool
36
37
iptablesError error
37
38
ipsetError error
@@ -85,23 +86,33 @@ func Test_getProxyMode(t *testing.T) {
85
86
kernelCompat : true ,
86
87
expected : proxyModeIPTables ,
87
88
},
88
- { // flag says ipvs, ipset version ok, kernel modules installed
89
- flag : "ipvs" ,
90
- kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack_ipv4" },
91
- ipsetVersion : ipvs .MinIPSetCheckVersion ,
92
- expected : proxyModeIPVS ,
89
+ { // flag says ipvs, ipset version ok, kernel modules installed for linux kernel before 4.19
90
+ flag : "ipvs" ,
91
+ kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack_ipv4" },
92
+ kernelVersion : "4.18" ,
93
+ ipsetVersion : ipvs .MinIPSetCheckVersion ,
94
+ expected : proxyModeIPVS ,
95
+ },
96
+ { // flag says ipvs, ipset version ok, kernel modules installed for linux kernel 4.19
97
+ flag : "ipvs" ,
98
+ kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack" },
99
+ kernelVersion : "4.19" ,
100
+ ipsetVersion : ipvs .MinIPSetCheckVersion ,
101
+ expected : proxyModeIPVS ,
93
102
},
94
103
{ // flag says ipvs, ipset version too low, fallback on iptables mode
95
104
flag : "ipvs" ,
96
- kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack_ipv4" },
105
+ kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack" },
106
+ kernelVersion : "4.19" ,
97
107
ipsetVersion : "0.0" ,
98
108
iptablesVersion : iptables .MinCheckVersion ,
99
109
kernelCompat : true ,
100
110
expected : proxyModeIPTables ,
101
111
},
102
112
{ // flag says ipvs, bad ipset version, fallback on iptables mode
103
113
flag : "ipvs" ,
104
- kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack_ipv4" },
114
+ kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack" },
115
+ kernelVersion : "4.19" ,
105
116
ipsetVersion : "a.b.c" ,
106
117
iptablesVersion : iptables .MinCheckVersion ,
107
118
kernelCompat : true ,
@@ -110,6 +121,7 @@ func Test_getProxyMode(t *testing.T) {
110
121
{ // flag says ipvs, required kernel modules are not installed, fallback on iptables mode
111
122
flag : "ipvs" ,
112
123
kmods : []string {"foo" , "bar" , "baz" },
124
+ kernelVersion : "4.19" ,
113
125
ipsetVersion : ipvs .MinIPSetCheckVersion ,
114
126
iptablesVersion : iptables .MinCheckVersion ,
115
127
kernelCompat : true ,
@@ -118,14 +130,25 @@ func Test_getProxyMode(t *testing.T) {
118
130
{ // flag says ipvs, required kernel modules are not installed, iptables version too old, fallback on userspace mode
119
131
flag : "ipvs" ,
120
132
kmods : []string {"foo" , "bar" , "baz" },
133
+ kernelVersion : "4.19" ,
134
+ ipsetVersion : ipvs .MinIPSetCheckVersion ,
135
+ iptablesVersion : "0.0.0" ,
136
+ kernelCompat : true ,
137
+ expected : proxyModeUserspace ,
138
+ },
139
+ { // flag says ipvs, required kernel modules are not installed, iptables version too old, fallback on userspace mode
140
+ flag : "ipvs" ,
141
+ kmods : []string {"foo" , "bar" , "baz" },
142
+ kernelVersion : "4.19" ,
121
143
ipsetVersion : ipvs .MinIPSetCheckVersion ,
122
144
iptablesVersion : "0.0.0" ,
123
145
kernelCompat : true ,
124
146
expected : proxyModeUserspace ,
125
147
},
126
148
{ // flag says ipvs, ipset version too low, iptables version too old, kernel not compatible, fallback on userspace mode
127
149
flag : "ipvs" ,
128
- kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack_ipv4" },
150
+ kmods : []string {"ip_vs" , "ip_vs_rr" , "ip_vs_wrr" , "ip_vs_sh" , "nf_conntrack" },
151
+ kernelVersion : "4.19" ,
129
152
ipsetVersion : "0.0" ,
130
153
iptablesVersion : iptables .MinCheckVersion ,
131
154
kernelCompat : false ,
@@ -136,7 +159,10 @@ func Test_getProxyMode(t *testing.T) {
136
159
versioner := & fakeIPTablesVersioner {c .iptablesVersion , c .iptablesError }
137
160
kcompater := & fakeKernelCompatTester {c .kernelCompat }
138
161
ipsetver := & fakeIPSetVersioner {c .ipsetVersion , c .ipsetError }
139
- khandler := & fakeKernelHandler {c .kmods }
162
+ khandler := & fakeKernelHandler {
163
+ modules : c .kmods ,
164
+ kernelVersion : c .kernelVersion ,
165
+ }
140
166
r := getProxyMode (c .flag , versioner , khandler , ipsetver , kcompater )
141
167
if r != c .expected {
142
168
t .Errorf ("Case[%d] Expected %q, got %q" , i , c .expected , r )
0 commit comments