sandbox.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. package libnetwork
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "net"
  7. "sort"
  8. "strings"
  9. "sync"
  10. "github.com/containerd/log"
  11. "github.com/docker/docker/libnetwork/etchosts"
  12. "github.com/docker/docker/libnetwork/osl"
  13. "github.com/docker/docker/libnetwork/types"
  14. "go.opentelemetry.io/otel"
  15. "go.opentelemetry.io/otel/attribute"
  16. "go.opentelemetry.io/otel/trace"
  17. )
  18. // SandboxOption is an option setter function type used to pass various options to
  19. // NewNetContainer method. The various setter functions of type SandboxOption are
  20. // provided by libnetwork, they look like ContainerOptionXXXX(...)
  21. type SandboxOption func(sb *Sandbox)
  22. func (sb *Sandbox) processOptions(options ...SandboxOption) {
  23. for _, opt := range options {
  24. if opt != nil {
  25. opt(sb)
  26. }
  27. }
  28. }
  29. // Sandbox provides the control over the network container entity.
  30. // It is a one to one mapping with the container.
  31. type Sandbox struct {
  32. id string
  33. containerID string
  34. config containerConfig
  35. extDNS []extDNSEntry
  36. osSbox *osl.Namespace
  37. controller *Controller
  38. resolver *Resolver
  39. resolverOnce sync.Once
  40. endpoints []*Endpoint
  41. epPriority map[string]int
  42. populatedEndpoints map[string]struct{}
  43. joinLeaveDone chan struct{}
  44. dbIndex uint64
  45. dbExists bool
  46. isStub bool
  47. inDelete bool
  48. ingress bool
  49. ndotsSet bool
  50. oslTypes []osl.SandboxType // slice of properties of this sandbox
  51. loadBalancerNID string // NID that this SB is a load balancer for
  52. mu sync.Mutex
  53. // This mutex is used to serialize service related operation for an endpoint
  54. // The lock is here because the endpoint is saved into the store so is not unique
  55. service sync.Mutex
  56. }
  57. // These are the container configs used to customize container /etc/hosts file.
  58. type hostsPathConfig struct {
  59. hostName string
  60. domainName string
  61. hostsPath string
  62. originHostsPath string
  63. extraHosts []extraHost
  64. parentUpdates []parentUpdate
  65. }
  66. type parentUpdate struct {
  67. cid string
  68. name string
  69. ip string
  70. }
  71. type extraHost struct {
  72. name string
  73. IP string
  74. }
  75. // These are the container configs used to customize container /etc/resolv.conf file.
  76. type resolvConfPathConfig struct {
  77. resolvConfPath string
  78. originResolvConfPath string
  79. resolvConfHashFile string
  80. dnsList []string
  81. dnsSearchList []string
  82. dnsOptionsList []string
  83. }
  84. type containerConfig struct {
  85. hostsPathConfig
  86. resolvConfPathConfig
  87. generic map[string]interface{}
  88. useDefaultSandBox bool
  89. useExternalKey bool
  90. exposedPorts []types.TransportPort
  91. }
  92. // ID returns the ID of the sandbox.
  93. func (sb *Sandbox) ID() string {
  94. return sb.id
  95. }
  96. // ContainerID returns the container id associated to this sandbox.
  97. func (sb *Sandbox) ContainerID() string {
  98. return sb.containerID
  99. }
  100. // Key returns the sandbox's key.
  101. func (sb *Sandbox) Key() string {
  102. if sb.config.useDefaultSandBox {
  103. return osl.GenerateKey("default")
  104. }
  105. return osl.GenerateKey(sb.id)
  106. }
  107. // Labels returns the sandbox's labels.
  108. func (sb *Sandbox) Labels() map[string]interface{} {
  109. sb.mu.Lock()
  110. defer sb.mu.Unlock()
  111. opts := make(map[string]interface{}, len(sb.config.generic))
  112. for k, v := range sb.config.generic {
  113. opts[k] = v
  114. }
  115. return opts
  116. }
  117. // Delete destroys this container after detaching it from all connected endpoints.
  118. func (sb *Sandbox) Delete() error {
  119. return sb.delete(false)
  120. }
  121. func (sb *Sandbox) delete(force bool) error {
  122. sb.mu.Lock()
  123. if sb.inDelete {
  124. sb.mu.Unlock()
  125. return types.ForbiddenErrorf("another sandbox delete in progress")
  126. }
  127. // Set the inDelete flag. This will ensure that we don't
  128. // update the store until we have completed all the endpoint
  129. // leaves and deletes. And when endpoint leaves and deletes
  130. // are completed then we can finally delete the sandbox object
  131. // altogether from the data store. If the daemon exits
  132. // ungracefully in the middle of a sandbox delete this way we
  133. // will have all the references to the endpoints in the
  134. // sandbox so that we can clean them up when we restart
  135. sb.inDelete = true
  136. sb.mu.Unlock()
  137. c := sb.controller
  138. // Detach from all endpoints
  139. retain := false
  140. for _, ep := range sb.Endpoints() {
  141. // gw network endpoint detach and removal are automatic
  142. if ep.endpointInGWNetwork() && !force {
  143. continue
  144. }
  145. // Retain the sanbdox if we can't obtain the network from store.
  146. if _, err := c.getNetworkFromStore(ep.getNetwork().ID()); err != nil {
  147. if !c.isSwarmNode() {
  148. retain = true
  149. }
  150. log.G(context.TODO()).Warnf("Failed getting network for ep %s during sandbox %s delete: %v", ep.ID(), sb.ID(), err)
  151. continue
  152. }
  153. if !force {
  154. if err := ep.Leave(sb); err != nil {
  155. log.G(context.TODO()).Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err)
  156. }
  157. }
  158. if err := ep.Delete(force); err != nil {
  159. log.G(context.TODO()).Warnf("Failed deleting endpoint %s: %v\n", ep.ID(), err)
  160. }
  161. }
  162. if retain {
  163. sb.mu.Lock()
  164. sb.inDelete = false
  165. sb.mu.Unlock()
  166. return fmt.Errorf("could not cleanup all the endpoints in container %s / sandbox %s", sb.containerID, sb.id)
  167. }
  168. // Container is going away. Path cache in etchosts is most
  169. // likely not required any more. Drop it.
  170. etchosts.Drop(sb.config.hostsPath)
  171. if sb.resolver != nil {
  172. sb.resolver.Stop()
  173. }
  174. if sb.osSbox != nil && !sb.config.useDefaultSandBox {
  175. if err := sb.osSbox.Destroy(); err != nil {
  176. log.G(context.TODO()).WithError(err).Warn("error destroying network sandbox")
  177. }
  178. }
  179. if err := sb.storeDelete(); err != nil {
  180. log.G(context.TODO()).Warnf("Failed to delete sandbox %s from store: %v", sb.ID(), err)
  181. }
  182. c.mu.Lock()
  183. if sb.ingress {
  184. c.ingressSandbox = nil
  185. }
  186. delete(c.sandboxes, sb.ID())
  187. c.mu.Unlock()
  188. return nil
  189. }
  190. // Rename changes the name of all attached Endpoints.
  191. func (sb *Sandbox) Rename(name string) error {
  192. var err error
  193. for _, ep := range sb.Endpoints() {
  194. if ep.endpointInGWNetwork() {
  195. continue
  196. }
  197. oldName := ep.Name()
  198. lEp := ep
  199. if err = ep.rename(name); err != nil {
  200. break
  201. }
  202. defer func() {
  203. if err != nil {
  204. if err2 := lEp.rename(oldName); err2 != nil {
  205. log.G(context.TODO()).WithField("old", oldName).WithField("origError", err).WithError(err2).Error("error renaming sandbox")
  206. }
  207. }
  208. }()
  209. }
  210. return err
  211. }
  212. // Refresh leaves all the endpoints, resets and re-applies the options,
  213. // re-joins all the endpoints without destroying the osl sandbox
  214. func (sb *Sandbox) Refresh(options ...SandboxOption) error {
  215. // Store connected endpoints
  216. epList := sb.Endpoints()
  217. // Detach from all endpoints
  218. for _, ep := range epList {
  219. if err := ep.Leave(sb); err != nil {
  220. log.G(context.TODO()).Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err)
  221. }
  222. }
  223. // Re-apply options
  224. sb.config = containerConfig{}
  225. sb.processOptions(options...)
  226. // Setup discovery files
  227. if err := sb.setupResolutionFiles(); err != nil {
  228. return err
  229. }
  230. // Re-connect to all endpoints
  231. for _, ep := range epList {
  232. if err := ep.Join(sb); err != nil {
  233. log.G(context.TODO()).Warnf("Failed attach sandbox %s to endpoint %s: %v\n", sb.ID(), ep.ID(), err)
  234. }
  235. }
  236. return nil
  237. }
  238. func (sb *Sandbox) MarshalJSON() ([]byte, error) {
  239. sb.mu.Lock()
  240. defer sb.mu.Unlock()
  241. // We are just interested in the container ID. This can be expanded to include all of containerInfo if there is a need
  242. return json.Marshal(sb.id)
  243. }
  244. func (sb *Sandbox) UnmarshalJSON(b []byte) (err error) {
  245. sb.mu.Lock()
  246. defer sb.mu.Unlock()
  247. var id string
  248. if err := json.Unmarshal(b, &id); err != nil {
  249. return err
  250. }
  251. sb.id = id
  252. return nil
  253. }
  254. // Endpoints returns all the endpoints connected to the sandbox.
  255. func (sb *Sandbox) Endpoints() []*Endpoint {
  256. sb.mu.Lock()
  257. defer sb.mu.Unlock()
  258. eps := make([]*Endpoint, len(sb.endpoints))
  259. copy(eps, sb.endpoints)
  260. return eps
  261. }
  262. func (sb *Sandbox) addEndpoint(ep *Endpoint) {
  263. sb.mu.Lock()
  264. defer sb.mu.Unlock()
  265. l := len(sb.endpoints)
  266. i := sort.Search(l, func(j int) bool {
  267. return ep.Less(sb.endpoints[j])
  268. })
  269. sb.endpoints = append(sb.endpoints, nil)
  270. copy(sb.endpoints[i+1:], sb.endpoints[i:])
  271. sb.endpoints[i] = ep
  272. }
  273. func (sb *Sandbox) removeEndpoint(ep *Endpoint) {
  274. sb.mu.Lock()
  275. defer sb.mu.Unlock()
  276. sb.removeEndpointRaw(ep)
  277. }
  278. func (sb *Sandbox) removeEndpointRaw(ep *Endpoint) {
  279. for i, e := range sb.endpoints {
  280. if e == ep {
  281. sb.endpoints = append(sb.endpoints[:i], sb.endpoints[i+1:]...)
  282. return
  283. }
  284. }
  285. }
  286. func (sb *Sandbox) GetEndpoint(id string) *Endpoint {
  287. sb.mu.Lock()
  288. defer sb.mu.Unlock()
  289. for _, ep := range sb.endpoints {
  290. if ep.id == id {
  291. return ep
  292. }
  293. }
  294. return nil
  295. }
  296. func (sb *Sandbox) HandleQueryResp(name string, ip net.IP) {
  297. for _, ep := range sb.Endpoints() {
  298. n := ep.getNetwork()
  299. n.HandleQueryResp(name, ip)
  300. }
  301. }
  302. func (sb *Sandbox) ResolveIP(ctx context.Context, ip string) string {
  303. var svc string
  304. log.G(ctx).Debugf("IP To resolve %v", ip)
  305. for _, ep := range sb.Endpoints() {
  306. n := ep.getNetwork()
  307. svc = n.ResolveIP(ctx, ip)
  308. if len(svc) != 0 {
  309. return svc
  310. }
  311. }
  312. return svc
  313. }
  314. // ResolveService returns all the backend details about the containers or hosts
  315. // backing a service. Its purpose is to satisfy an SRV query.
  316. func (sb *Sandbox) ResolveService(ctx context.Context, name string) ([]*net.SRV, []net.IP) {
  317. log.G(ctx).Debugf("Service name To resolve: %v", name)
  318. // There are DNS implementations that allow SRV queries for names not in
  319. // the format defined by RFC 2782. Hence specific validations checks are
  320. // not done
  321. if parts := strings.SplitN(name, ".", 3); len(parts) < 3 {
  322. return nil, nil
  323. }
  324. for _, ep := range sb.Endpoints() {
  325. n := ep.getNetwork()
  326. srv, ip := n.ResolveService(ctx, name)
  327. if len(srv) > 0 {
  328. return srv, ip
  329. }
  330. }
  331. return nil, nil
  332. }
  333. func (sb *Sandbox) ResolveName(ctx context.Context, name string, ipType int) ([]net.IP, bool) {
  334. // Embedded server owns the docker network domain. Resolution should work
  335. // for both container_name and container_name.network_name
  336. // We allow '.' in service name and network name. For a name a.b.c.d the
  337. // following have to tried;
  338. // {a.b.c.d in the networks container is connected to}
  339. // {a.b.c in network d},
  340. // {a.b in network c.d},
  341. // {a in network b.c.d},
  342. log.G(ctx).Debugf("Name To resolve: %v", name)
  343. name = strings.TrimSuffix(name, ".")
  344. reqName := []string{name}
  345. networkName := []string{""}
  346. if strings.Contains(name, ".") {
  347. var i int
  348. dup := name
  349. for {
  350. if i = strings.LastIndex(dup, "."); i == -1 {
  351. break
  352. }
  353. networkName = append(networkName, name[i+1:])
  354. reqName = append(reqName, name[:i])
  355. dup = dup[:i]
  356. }
  357. }
  358. epList := sb.Endpoints()
  359. // In swarm mode, services with exposed ports are connected to user overlay
  360. // network, ingress network and docker_gwbridge networks. Name resolution
  361. // should prioritize returning the VIP/IPs on user overlay network.
  362. //
  363. // Re-order the endpoints based on the network-type they're attached to;
  364. //
  365. // 1. dynamic networks (user overlay networks)
  366. // 2. ingress network(s)
  367. // 3. local networks ("docker_gwbridge")
  368. if sb.controller.isSwarmNode() {
  369. sort.Sort(ByNetworkType(epList))
  370. }
  371. for i := 0; i < len(reqName); i++ {
  372. // First check for local container alias
  373. ip, ipv6Miss := sb.resolveName(ctx, reqName[i], networkName[i], epList, true, ipType)
  374. if ip != nil {
  375. return ip, false
  376. }
  377. if ipv6Miss {
  378. return ip, ipv6Miss
  379. }
  380. // Resolve the actual container name
  381. ip, ipv6Miss = sb.resolveName(ctx, reqName[i], networkName[i], epList, false, ipType)
  382. if ip != nil {
  383. return ip, false
  384. }
  385. if ipv6Miss {
  386. return ip, ipv6Miss
  387. }
  388. }
  389. return nil, false
  390. }
  391. func (sb *Sandbox) resolveName(ctx context.Context, nameOrAlias string, networkName string, epList []*Endpoint, lookupAlias bool, ipType int) (_ []net.IP, ipv6Miss bool) {
  392. ctx, span := otel.Tracer("").Start(ctx, "Sandbox.resolveName", trace.WithAttributes(
  393. attribute.String("libnet.resolver.name-or-alias", nameOrAlias),
  394. attribute.String("libnet.network.name", networkName),
  395. attribute.Bool("libnet.resolver.alias-lookup", lookupAlias),
  396. attribute.Int("libnet.resolver.ip-family", ipType)))
  397. defer span.End()
  398. for _, ep := range epList {
  399. if lookupAlias && len(ep.aliases) == 0 {
  400. continue
  401. }
  402. nw := ep.getNetwork()
  403. if networkName != "" && networkName != nw.Name() {
  404. continue
  405. }
  406. name := nameOrAlias
  407. if lookupAlias {
  408. ep.mu.Lock()
  409. alias, ok := ep.aliases[nameOrAlias]
  410. ep.mu.Unlock()
  411. if !ok {
  412. continue
  413. }
  414. name = alias
  415. } else {
  416. // If it is a regular lookup and if the requested name is an alias
  417. // don't perform a svc lookup for this endpoint.
  418. ep.mu.Lock()
  419. _, ok := ep.aliases[nameOrAlias]
  420. ep.mu.Unlock()
  421. if ok {
  422. continue
  423. }
  424. }
  425. ip, miss := nw.ResolveName(ctx, name, ipType)
  426. if ip != nil {
  427. return ip, false
  428. }
  429. if miss {
  430. ipv6Miss = miss
  431. }
  432. }
  433. return nil, ipv6Miss
  434. }
  435. // EnableService makes a managed container's service available by adding the
  436. // endpoint to the service load balancer and service discovery.
  437. func (sb *Sandbox) EnableService() (err error) {
  438. log.G(context.TODO()).Debugf("EnableService %s START", sb.containerID)
  439. defer func() {
  440. if err != nil {
  441. if err2 := sb.DisableService(); err2 != nil {
  442. log.G(context.TODO()).WithError(err2).WithField("origError", err).Error("Error while disabling service after original error")
  443. }
  444. }
  445. }()
  446. for _, ep := range sb.Endpoints() {
  447. if !ep.isServiceEnabled() {
  448. if err := ep.addServiceInfoToCluster(sb); err != nil {
  449. return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
  450. }
  451. ep.enableService()
  452. }
  453. }
  454. log.G(context.TODO()).Debugf("EnableService %s DONE", sb.containerID)
  455. return nil
  456. }
  457. // DisableService removes a managed container's endpoints from the load balancer
  458. // and service discovery.
  459. func (sb *Sandbox) DisableService() (err error) {
  460. log.G(context.TODO()).Debugf("DisableService %s START", sb.containerID)
  461. failedEps := []string{}
  462. defer func() {
  463. if len(failedEps) > 0 {
  464. err = fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
  465. }
  466. }()
  467. for _, ep := range sb.Endpoints() {
  468. if ep.isServiceEnabled() {
  469. if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil {
  470. failedEps = append(failedEps, ep.Name())
  471. log.G(context.TODO()).Warnf("failed update state for endpoint %s into cluster: %v", ep.Name(), err)
  472. }
  473. ep.disableService()
  474. }
  475. }
  476. log.G(context.TODO()).Debugf("DisableService %s DONE", sb.containerID)
  477. return nil
  478. }
  479. func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
  480. ep := sb.GetEndpoint(origEp.id)
  481. if ep == nil {
  482. return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
  483. origEp.id)
  484. }
  485. sb.mu.Lock()
  486. osSbox := sb.osSbox
  487. inDelete := sb.inDelete
  488. sb.mu.Unlock()
  489. if osSbox != nil {
  490. releaseOSSboxResources(osSbox, ep)
  491. }
  492. sb.mu.Lock()
  493. delete(sb.populatedEndpoints, ep.ID())
  494. if len(sb.endpoints) == 0 {
  495. // sb.endpoints should never be empty and this is unexpected error condition
  496. // We log an error message to note this down for debugging purposes.
  497. log.G(context.TODO()).Errorf("No endpoints in sandbox while trying to remove endpoint %s", ep.Name())
  498. sb.mu.Unlock()
  499. return nil
  500. }
  501. var (
  502. gwepBefore, gwepAfter *Endpoint
  503. index = -1
  504. )
  505. for i, e := range sb.endpoints {
  506. if e == ep {
  507. index = i
  508. }
  509. if len(e.Gateway()) > 0 && gwepBefore == nil {
  510. gwepBefore = e
  511. }
  512. if index != -1 && gwepBefore != nil {
  513. break
  514. }
  515. }
  516. if index == -1 {
  517. log.G(context.TODO()).Warnf("Endpoint %s has already been deleted", ep.Name())
  518. sb.mu.Unlock()
  519. return nil
  520. }
  521. sb.removeEndpointRaw(ep)
  522. for _, e := range sb.endpoints {
  523. if len(e.Gateway()) > 0 {
  524. gwepAfter = e
  525. break
  526. }
  527. }
  528. delete(sb.epPriority, ep.ID())
  529. sb.mu.Unlock()
  530. if gwepAfter != nil && gwepBefore != gwepAfter {
  531. if err := sb.updateGateway(gwepAfter); err != nil {
  532. return err
  533. }
  534. }
  535. // Only update the store if we did not come here as part of
  536. // sandbox delete. If we came here as part of delete then do
  537. // not bother updating the store. The sandbox object will be
  538. // deleted anyway
  539. if !inDelete {
  540. return sb.storeUpdate()
  541. }
  542. return nil
  543. }
  544. // joinLeaveStart waits to ensure there are no joins or leaves in progress and
  545. // marks this join/leave in progress without race
  546. func (sb *Sandbox) joinLeaveStart() {
  547. sb.mu.Lock()
  548. defer sb.mu.Unlock()
  549. for sb.joinLeaveDone != nil {
  550. joinLeaveDone := sb.joinLeaveDone
  551. sb.mu.Unlock()
  552. <-joinLeaveDone
  553. sb.mu.Lock()
  554. }
  555. sb.joinLeaveDone = make(chan struct{})
  556. }
  557. // joinLeaveEnd marks the end of this join/leave operation and
  558. // signals the same without race to other join and leave waiters
  559. func (sb *Sandbox) joinLeaveEnd() {
  560. sb.mu.Lock()
  561. defer sb.mu.Unlock()
  562. if sb.joinLeaveDone != nil {
  563. close(sb.joinLeaveDone)
  564. sb.joinLeaveDone = nil
  565. }
  566. }
  567. // <=> Returns true if a < b, false if a > b and advances to next level if a == b
  568. // epi.prio <=> epj.prio # 2 < 1
  569. // epi.gw <=> epj.gw # non-gw < gw
  570. // epi.internal <=> epj.internal # non-internal < internal
  571. // epi.joininfo <=> epj.joininfo # ipv6 < ipv4
  572. // epi.name <=> epj.name # bar < foo
  573. func (epi *Endpoint) Less(epj *Endpoint) bool {
  574. var prioi, prioj int
  575. sbi, _ := epi.getSandbox()
  576. sbj, _ := epj.getSandbox()
  577. // Prio defaults to 0
  578. if sbi != nil {
  579. prioi = sbi.epPriority[epi.ID()]
  580. }
  581. if sbj != nil {
  582. prioj = sbj.epPriority[epj.ID()]
  583. }
  584. if prioi != prioj {
  585. return prioi > prioj
  586. }
  587. gwi := epi.endpointInGWNetwork()
  588. gwj := epj.endpointInGWNetwork()
  589. if gwi != gwj {
  590. return gwj
  591. }
  592. inti := epi.getNetwork().Internal()
  593. intj := epj.getNetwork().Internal()
  594. if inti != intj {
  595. return intj
  596. }
  597. jii := 0
  598. if epi.joinInfo != nil {
  599. if epi.joinInfo.gw != nil {
  600. jii = jii + 1
  601. }
  602. if epi.joinInfo.gw6 != nil {
  603. jii = jii + 2
  604. }
  605. }
  606. jij := 0
  607. if epj.joinInfo != nil {
  608. if epj.joinInfo.gw != nil {
  609. jij = jij + 1
  610. }
  611. if epj.joinInfo.gw6 != nil {
  612. jij = jij + 2
  613. }
  614. }
  615. if jii != jij {
  616. return jii > jij
  617. }
  618. return epi.network.Name() < epj.network.Name()
  619. }
  620. func (sb *Sandbox) NdotsSet() bool {
  621. return sb.ndotsSet
  622. }