@@ -122,8 +122,8 @@ func loadNetConf(bytes []byte, envArgs string) (*NetConf, string, error) {
122
122
123
123
// calcGateways processes the results from the IPAM plugin and does the
124
124
// following for each IP family:
125
- // - Calculates and compiles a list of gateway addresses
126
- // - Adds a default route if needed
125
+ // - Calculates and compiles a list of gateway addresses
126
+ // - Adds a default route if needed
127
127
func calcGateways (result * current.Result , n * NetConf ) (* gwInfo , * gwInfo , error ) {
128
128
129
129
gwsV4 := & gwInfo {}
@@ -681,6 +681,119 @@ func main() {
681
681
}
682
682
683
683
func cmdCheck (args * skel.CmdArgs ) error {
684
- // TODO: implement
685
- return fmt .Errorf ("not implemented" )
684
+ n , _ , err := loadNetConf (args .StdinData , args .Args )
685
+ if err != nil {
686
+ return err
687
+ }
688
+
689
+ // run the IPAM plugin and get back the config to apply
690
+ err = ipam .ExecCheck (n .IPAM .Type , args .StdinData )
691
+ if err != nil {
692
+ return err
693
+ }
694
+
695
+ // Parse previous result.
696
+ if n .NetConf .RawPrevResult == nil {
697
+ return fmt .Errorf ("Required prevResult missing" )
698
+ }
699
+
700
+ if err := version .ParsePrevResult (& n .NetConf ); err != nil {
701
+ return err
702
+ }
703
+
704
+ result , err := current .NewResultFromResult (n .PrevResult )
705
+ if err != nil {
706
+ return err
707
+ }
708
+
709
+ var contMap current.Interface
710
+
711
+ // Find interfaces for names whe know, CNI Bridge and container
712
+ for _ , intf := range result .Interfaces {
713
+ /*if n.BrName == intf.Name {
714
+ brMap = *intf
715
+ continue
716
+ } else*/ if args .IfName == intf .Name {
717
+ if args .Netns == intf .Sandbox {
718
+ contMap = * intf
719
+ continue
720
+ }
721
+ }
722
+ }
723
+
724
+ /*brCNI, err := validateCniBrInterface(brMap, n)
725
+ if err != nil {
726
+ return err
727
+ }*/
728
+
729
+ // The namespace must be the same as what was configured
730
+ if args .Netns != contMap .Sandbox {
731
+ return fmt .Errorf ("Sandbox in prevResult %s doesn't match configured netns: %s" ,
732
+ contMap .Sandbox , args .Netns )
733
+ }
734
+
735
+ // Check interface against values found in the container
736
+ /*if err := netns.Do(func(_ ns.NetNS) error {
737
+ contCNI, errLink = validateCniContainerInterface(contMap)
738
+ if errLink != nil {
739
+ return errLink
740
+ }
741
+ return nil
742
+ }); err != nil {
743
+ return err
744
+ }*/
745
+
746
+ // Now look for veth that is peer with container interface.
747
+ // Anything else wasn't created by CNI, skip it
748
+ /*for _, intf := range result.Interfaces {
749
+ // Skip this result if name is the same as cni bridge
750
+ // It's either the cni bridge we dealt with above, or something with the
751
+ // same name in a different namespace. We just skip since it's not ours
752
+ if brMap.Name == intf.Name {
753
+ continue
754
+ }
755
+
756
+ // same here for container name
757
+ if contMap.Name == intf.Name {
758
+ continue
759
+ }
760
+
761
+ vethCNI, errLink = validateCniVethInterface(intf, brCNI, contCNI)
762
+ if errLink != nil {
763
+ return errLink
764
+ }
765
+
766
+ if vethCNI.found {
767
+ // veth with container interface as peer and bridge as master found
768
+ break
769
+ }
770
+ }*/
771
+
772
+ /*if !brCNI.found {
773
+ return fmt.Errorf("CNI created bridge %s in host namespace was not found", n.BrName)
774
+ }
775
+ if !contCNI.found {
776
+ return fmt.Errorf("CNI created interface in container %s not found", args.IfName)
777
+ }
778
+ if !vethCNI.found {
779
+ return fmt.Errorf("CNI veth created for bridge %s was not found", n.BrName)
780
+ }*/
781
+
782
+ // Check prevResults for ips, routes and dns against values found in the container
783
+ /*if err := netns.Do(func(_ ns.NetNS) error {
784
+ err = ip.ValidateExpectedInterfaceIPs(args.IfName, result.IPs)
785
+ if err != nil {
786
+ return err
787
+ }
788
+
789
+ err = ip.ValidateExpectedRoute(result.Routes)
790
+ if err != nil {
791
+ return err
792
+ }
793
+ return nil
794
+ }); err != nil {
795
+ return err
796
+ }*/
797
+
798
+ return nil
686
799
}
0 commit comments