gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/libinit/net_linux.go (about)

     1  // Copyright 2014-2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package libinit
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/u-root/u-root/pkg/ulog"
    11  	"github.com/vishvananda/netlink"
    12  )
    13  
    14  // NetInit is u-root network initialization.
    15  func linuxNetInit() {
    16  	if err := loopbackUp(); err != nil {
    17  		ulog.KernelLog.Printf("Failed to initialize loopback: %v", err)
    18  	}
    19  }
    20  
    21  func loopbackUp() error {
    22  	lo, err := netlink.LinkByName("lo")
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	if err := netlink.LinkSetUp(lo); err != nil {
    28  		return fmt.Errorf("couldn't set link loopback up: %v", err)
    29  	}
    30  	return nil
    31  }
    32  
    33  func init() {
    34  	osNetInit = linuxNetInit
    35  }