@@ -93,20 +93,29 @@ func iptables(args ...string) error {
9393 return nil
9494}
9595
96- func checkRouteOverlaps (dockerNetwork * net.IPNet ) error {
97- output , err := ip ("route" )
98- if err != nil {
99- return err
100- }
101- utils .Debugf ("Routes:\n \n %s" , output )
102- for _ , line := range strings .Split (output , "\n " ) {
96+ func checkRouteOverlaps (routes string , dockerNetwork * net.IPNet ) error {
97+ utils .Debugf ("Routes:\n \n %s" , routes )
98+ for _ , line := range strings .Split (routes , "\n " ) {
10399 if strings .Trim (line , "\r \n \t " ) == "" || strings .Contains (line , "default" ) {
104100 continue
105101 }
106- if _ , network , err := net .ParseCIDR (strings .Split (line , " " )[0 ]); err != nil {
107- return fmt .Errorf ("Unexpected ip route output: %s (%s)" , err , line )
108- } else if networkOverlaps (dockerNetwork , network ) {
109- return fmt .Errorf ("Network %s is already routed: '%s'" , dockerNetwork .String (), line )
102+ _ , network , err := net .ParseCIDR (strings .Split (line , " " )[0 ])
103+ if err != nil {
104+ // is this a mask-less IP address?
105+ if ip := net .ParseIP (strings .Split (line , " " )[0 ]); ip == nil {
106+ // fail only if it's neither a network nor a mask-less IP address
107+ return fmt .Errorf ("Unexpected ip route output: %s (%s)" , err , line )
108+ } else {
109+ _ , network , err = net .ParseCIDR (ip .String () + "/32" )
110+ if err != nil {
111+ return err
112+ }
113+ }
114+ }
115+ if err == nil && network != nil {
116+ if networkOverlaps (dockerNetwork , network ) {
117+ return fmt .Errorf ("Network %s is already routed: '%s'" , dockerNetwork , line )
118+ }
110119 }
111120 }
112121 return nil
@@ -142,7 +151,11 @@ func CreateBridgeIface(ifaceName string) error {
142151 if err != nil {
143152 return err
144153 }
145- if err := checkRouteOverlaps (dockerNetwork ); err == nil {
154+ routes , err := ip ("route" )
155+ if err != nil {
156+ return err
157+ }
158+ if err := checkRouteOverlaps (routes , dockerNetwork ); err == nil {
146159 ifaceAddr = addr
147160 break
148161 } else {
0 commit comments