@@ -225,6 +225,10 @@ func (plugin *OsdnNode) SetupSDN() (bool, error) {
225
225
if err != nil {
226
226
return false , err
227
227
}
228
+ err = plugin .ovs .SetFrags ("nx-match" )
229
+ if err != nil {
230
+ return false , err
231
+ }
228
232
_ = plugin .ovs .DeletePort (VXLAN )
229
233
_ , err = plugin .ovs .AddPort (VXLAN , 1 , "type=vxlan" , `options:remote_ip="flow"` , `options:key="flow"` )
230
234
if err != nil {
@@ -457,35 +461,44 @@ func (plugin *OsdnNode) AddServiceRules(service *kapi.Service, netID uint32) {
457
461
glog .V (5 ).Infof ("AddServiceRules for %v" , service )
458
462
459
463
otx := plugin .ovs .NewTransaction ()
464
+ action := fmt .Sprintf (", priority=100, actions=load:%d->NXM_NX_REG1[], load:2->NXM_NX_REG2[], goto_table:80" , netID )
465
+
466
+ // Add blanket rule allowing subsequent IP fragments
467
+ otx .AddFlow (generateBaseServiceRule (service .Spec .ClusterIP ) + ", ip_frag=later" + action )
468
+
460
469
for _ , port := range service .Spec .Ports {
461
- otx . AddFlow ( generateAddServiceRule ( netID , service .Spec .ClusterIP , port .Protocol , int (port .Port ) ))
462
- if err := otx . EndTransaction (); err != nil {
463
- glog .Errorf ("Error adding OVS flows for service %v, netid %d: %v" , service , netID , err )
470
+ baseRule , err := generateBaseAddServiceRule ( service .Spec .ClusterIP , port .Protocol , int (port .Port ))
471
+ if err != nil {
472
+ glog .Errorf ("Error creating OVS flow for service %v, netid %d: %v" , service , netID , err )
464
473
}
474
+ otx .AddFlow (baseRule + action )
475
+ }
476
+
477
+ if err := otx .EndTransaction (); err != nil {
478
+ glog .Errorf ("Error adding OVS flows for service %v, netid %d: %v" , service , netID , err )
465
479
}
466
480
}
467
481
468
482
func (plugin * OsdnNode ) DeleteServiceRules (service * kapi.Service ) {
469
483
glog .V (5 ).Infof ("DeleteServiceRules for %v" , service )
470
484
471
485
otx := plugin .ovs .NewTransaction ()
472
- for _ , port := range service .Spec .Ports {
473
- otx .DeleteFlows (generateDeleteServiceRule (service .Spec .ClusterIP , port .Protocol , int (port .Port )))
474
- if err := otx .EndTransaction (); err != nil {
475
- glog .Errorf ("Error deleting OVS flows for service %v: %v" , service , err )
476
- }
477
- }
486
+ otx .DeleteFlows (generateBaseServiceRule (service .Spec .ClusterIP ))
487
+ otx .EndTransaction ()
478
488
}
479
489
480
- func generateBaseServiceRule (IP string , protocol kapi. Protocol , port int ) string {
481
- return fmt .Sprintf ("table=60, %s , nw_dst=%s, tp_dst=%d " , strings . ToLower ( string ( protocol )), IP , port )
490
+ func generateBaseServiceRule (IP string ) string {
491
+ return fmt .Sprintf ("table=60, ip , nw_dst=%s" , IP )
482
492
}
483
493
484
- func generateAddServiceRule (netID uint32 , IP string , protocol kapi.Protocol , port int ) string {
485
- baseRule := generateBaseServiceRule (IP , protocol , port )
486
- return fmt .Sprintf ("%s, priority=100, actions=load:%d->NXM_NX_REG1[], load:2->NXM_NX_REG2[], goto_table:80" , baseRule , netID )
487
- }
488
-
489
- func generateDeleteServiceRule (IP string , protocol kapi.Protocol , port int ) string {
490
- return generateBaseServiceRule (IP , protocol , port )
494
+ func generateBaseAddServiceRule (IP string , protocol kapi.Protocol , port int ) (string , error ) {
495
+ var dst string
496
+ if protocol == kapi .ProtocolUDP {
497
+ dst = fmt .Sprintf (", udp, udp_dst=%d" , port )
498
+ } else if protocol == kapi .ProtocolTCP {
499
+ dst = fmt .Sprintf (", tcp, tcp_dst=%d" , port )
500
+ } else {
501
+ return "" , fmt .Errorf ("unhandled protocol %v" , protocol )
502
+ }
503
+ return generateBaseServiceRule (IP ) + dst , nil
491
504
}
0 commit comments