@@ -31,9 +31,13 @@ func (t NodeType) String() string {
3131}
3232
3333const (
34- forceEncryptTable = 100
35- exemptPrio = 200
36- encryptPrio = exemptPrio + 1
34+ forceEncryptTableId = 100
35+ // Always encrypt remote pod traffic
36+ remotePodPrio = 200
37+ // Don't encrypt exempted ports
38+ exemptPrio = remotePodPrio + 10
39+ // Encrypt everything else to remote nodes
40+ encryptPrio = exemptPrio + 10
3741)
3842
3943// Reconciler runs the async reconciliation loop
@@ -110,6 +114,11 @@ func (r *Reconciler) debounceAndReconcile(ctx context.Context, ticker *time.Tick
110114 }
111115}
112116
117+ type netWithPrio struct {
118+ net net.IPNet
119+ prio int
120+ }
121+
113122func (r * Reconciler ) reconcile (ctx context.Context ) {
114123 start := time .Now ()
115124
@@ -118,7 +127,7 @@ func (r *Reconciler) reconcile(ctx context.Context) {
118127 r .state .Lock ()
119128 defer r .state .Unlock ()
120129
121- encryptIPs := make (map [string ]* net. IPNet )
130+ encryptIPs := make (map [string ]* netWithPrio )
122131 exemptIPs := make (map [string ]* net.IPNet )
123132 needSetup := false
124133 var nodeType NodeType
@@ -144,15 +153,21 @@ func (r *Reconciler) reconcile(ctx context.Context) {
144153 for _ , cidr := range node .Spec .IPAM .PodCIDRs {
145154 dst := parseIPv4OrCIDR (cidr )
146155 if dst != nil {
147- encryptIPs [cidr ] = dst
156+ encryptIPs [cidr ] = & netWithPrio {
157+ net : * dst ,
158+ prio : remotePodPrio ,
159+ }
148160 }
149161 }
150162 for _ , addrspec := range node .Spec .Addresses {
151163 if addrspec .Type == "InternalIP" {
152164 addr := addrspec .IP
153165 dstNet := parseIPv4OrCIDR (addr )
154166 if dstNet != nil {
155- encryptIPs [addr ] = dstNet
167+ encryptIPs [addr ] = & netWithPrio {
168+ net : * dstNet ,
169+ prio : encryptPrio ,
170+ }
156171 if nodeType == NodeTypeControlPlane {
157172 exemptIPs [addr ] = dstNet
158173 }
@@ -211,9 +226,11 @@ func (r *Reconciler) reconcile(ctx context.Context) {
211226
212227 }
213228 for dst := range sets .KeySet (encryptIPs ).Difference (r .readyRoutes ) {
214- dstNet := encryptIPs [dst ]
229+ ruleData := encryptIPs [dst ]
215230 err = nil
216- if err = r .ensureRule (buildEncryptionRule (dstNet )); err == nil {
231+ rule := buildEncryptionRule (& ruleData .net )
232+ rule .Priority = ruleData .prio
233+ if err = r .ensureRule (rule ); err == nil {
217234 r .readyRoutes .Insert (dst )
218235 }
219236 }
@@ -288,10 +305,8 @@ func buildRule(dst *net.IPNet, exempt bool) *netlink.Rule {
288305 rule .Dst = dst
289306 if exempt {
290307 rule .Table = unix .RT_TABLE_MAIN
291- rule .Priority = exemptPrio
292308 } else {
293- rule .Table = forceEncryptTable
294- rule .Priority = encryptPrio
309+ rule .Table = forceEncryptTableId
295310 }
296311 return rule
297312}
@@ -304,6 +319,7 @@ func (r Reconciler) buildExemptRules(dst *net.IPNet) []*netlink.Rule {
304319 rules := make ([]* netlink.Rule , 0 )
305320 for _ , portRange := range r .options .ControlPlaneExemptPorts {
306321 rule := buildRule (dst , true )
322+ rule .Priority = exemptPrio
307323 rule .Dport = & portRange
308324 rules = append (rules , rule )
309325 }
@@ -357,7 +373,7 @@ func (r *Reconciler) setup() {
357373 IP : net .ParseIP ("0.0.0.0" ),
358374 Mask : net .CIDRMask (0 , 32 ),
359375 },
360- Table : forceEncryptTable ,
376+ Table : forceEncryptTableId ,
361377 }
362378
363379 err := netlink .RouteAdd (route )
0 commit comments