mirror of https://github.com/jetkvm/kvm.git
Compare commits
3 Commits
d4ca1574ee
...
e7b2562b7b
Author | SHA1 | Date |
---|---|---|
|
e7b2562b7b | |
|
63b3ef0151 | |
|
1e589ede16 |
37
network.go
37
network.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"golang.org/x/net/ipv4"
|
"golang.org/x/net/ipv4"
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"net"
|
"net"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
@ -25,6 +26,23 @@ type LocalIpInfo struct {
|
||||||
MAC string
|
MAC string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setDhcpClientState sends signals to udhcpc to change it's current mode
|
||||||
|
// of operation. Setting active to true will force udhcpc to renew the DHCP lease.
|
||||||
|
// Setting active to false will put udhcpc into idle mode.
|
||||||
|
func setDhcpClientState(active bool) {
|
||||||
|
var signal string;
|
||||||
|
if active {
|
||||||
|
signal = "-SIGUSR1"
|
||||||
|
} else {
|
||||||
|
signal = "-SIGUSR2"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("/usr/bin/killall", signal, "udhcpc");
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Printf("network: setDhcpClientState: failed to change udhcpc state: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func checkNetworkState() {
|
func checkNetworkState() {
|
||||||
iface, err := netlink.LinkByName("eth0")
|
iface, err := netlink.LinkByName("eth0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,9 +65,26 @@ func checkNetworkState() {
|
||||||
fmt.Printf("failed to get addresses for eth0: %v\n", err)
|
fmt.Printf("failed to get addresses for eth0: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the link is going down, put udhcpc into idle mode.
|
||||||
|
// If the link is coming back up, activate udhcpc and force it to renew the lease.
|
||||||
|
if newState.Up != networkState.Up {
|
||||||
|
setDhcpClientState(newState.Up)
|
||||||
|
}
|
||||||
|
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if addr.IP.To4() != nil {
|
if addr.IP.To4() != nil {
|
||||||
newState.IPv4 = addr.IP.String()
|
if !newState.Up && networkState.Up {
|
||||||
|
// If the network is going down, remove all IPv4 addresses from the interface.
|
||||||
|
fmt.Printf("network: state transitioned to down, removing IPv4 address %s\n", addr.IP.String())
|
||||||
|
err := netlink.AddrDel(iface, &addr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("network: failed to delete %s", addr.IP.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
newState.IPv4 = "..."
|
||||||
|
} else {
|
||||||
|
newState.IPv4 = addr.IP.String()
|
||||||
|
}
|
||||||
} else if addr.IP.To16() != nil && newState.IPv6 == "" {
|
} else if addr.IP.To16() != nil && newState.IPv6 == "" {
|
||||||
newState.IPv6 = addr.IP.String()
|
newState.IPv6 = addr.IP.String()
|
||||||
}
|
}
|
||||||
|
|
4
usb.go
4
usb.go
|
@ -132,7 +132,7 @@ func writeGadgetConfig() error {
|
||||||
}
|
}
|
||||||
err = writeGadgetAttrs(hid0Path, [][]string{
|
err = writeGadgetAttrs(hid0Path, [][]string{
|
||||||
{"protocol", "1"},
|
{"protocol", "1"},
|
||||||
{"subclass", "0"},
|
{"subclass", "1"},
|
||||||
{"report_length", "8"},
|
{"report_length", "8"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -152,7 +152,7 @@ func writeGadgetConfig() error {
|
||||||
}
|
}
|
||||||
err = writeGadgetAttrs(hid1Path, [][]string{
|
err = writeGadgetAttrs(hid1Path, [][]string{
|
||||||
{"protocol", "2"},
|
{"protocol", "2"},
|
||||||
{"subclass", "0"},
|
{"subclass", "1"},
|
||||||
{"report_length", "6"},
|
{"report_length", "6"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue