WIP on start, go fmt on *

This commit is contained in:
yo
2022-04-24 16:49:54 +02:00
parent dbd9153513
commit 43f26d099f
12 changed files with 1498 additions and 1169 deletions

View File

@ -2,8 +2,8 @@ package cmd
import (
"fmt"
"net"
"golang.org/x/net/route"
"net"
)
var defaultRoute4 = [4]byte{0, 0, 0, 0}
@ -15,9 +15,9 @@ func Inet4AddrToString(ip4 route.Inet4Addr) string {
}
func Inet6AddrToString(ip6 route.Inet6Addr) string {
return fmt.Sprintf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
ip6.IP[0], ip6.IP[1], ip6.IP[2], ip6.IP[3], ip6.IP[4], ip6.IP[5], ip6.IP[6], ip6.IP[7],
ip6.IP[8], ip6.IP[9], ip6.IP[10], ip6.IP[11], ip6.IP[12], ip6.IP[13], ip6.IP[14], ip6.IP[15])
return fmt.Sprintf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
ip6.IP[0], ip6.IP[1], ip6.IP[2], ip6.IP[3], ip6.IP[4], ip6.IP[5], ip6.IP[6], ip6.IP[7],
ip6.IP[8], ip6.IP[9], ip6.IP[10], ip6.IP[11], ip6.IP[12], ip6.IP[13], ip6.IP[14], ip6.IP[15])
}
/*****************************************************************************
@ -29,28 +29,28 @@ func (jh *JailHost) InitNetworkProperties() {
if err != nil {
panic(err)
}
for _, message := range messages {
route_message := message.(*route.RouteMessage)
addresses := route_message.Addrs
card_index := route_message.Index
if addresses[0].Family() == 2 {
var destination4, gateway4 *route.Inet4Addr
ok := false
if destination4, ok = addresses[0].(*route.Inet4Addr); !ok {
continue
}
if gateway4, ok = addresses[1].(*route.Inet4Addr); !ok {
continue
}
if destination4 == nil || gateway4 == nil {
continue
}
if destination4.IP == defaultRoute4 {
card, _ := net.InterfaceByIndex(card_index)
//fmt.Printf("Default IPv4 gateway is %v on card %s\n", Inet4AddrToString(*gateway4), card.Name)
@ -60,19 +60,19 @@ func (jh *JailHost) InitNetworkProperties() {
} else if addresses[0].Family() == 28 {
var destination6, gateway6 *route.Inet6Addr
ok := false
if destination6, ok = addresses[0].(*route.Inet6Addr); !ok {
continue
}
if gateway6, ok = addresses[1].(*route.Inet6Addr); !ok {
continue
}
if destination6 == nil || gateway6 == nil {
continue
}
if destination6.IP == defaultRoute6 && gateway6.IP != local6 {
card, _ := net.InterfaceByIndex(card_index)
//fmt.Printf("Default IPv6 gateway is %v on card %s\n", Inet6AddrToString(*gateway6), card.Name)
@ -83,7 +83,6 @@ func (jh *JailHost) InitNetworkProperties() {
}
}
func (jh *JailHost) GetDefaultInterface() string {
if len(jh.default_interface) == 0 {
jh.InitNetworkProperties()
@ -91,7 +90,6 @@ func (jh *JailHost) GetDefaultInterface() string {
return jh.default_interface
}
func (jh *JailHost) GetDefaultGateway4() string {
if len(jh.default_gateway4) == 0 {
jh.InitNetworkProperties()
@ -99,11 +97,9 @@ func (jh *JailHost) GetDefaultGateway4() string {
return jh.default_gateway4
}
func(jh *JailHost) GetDefaultGateway6() string {
func (jh *JailHost) GetDefaultGateway6() string {
if len(jh.default_gateway6) == 0 {
jh.InitNetworkProperties()
}
return jh.default_gateway6
}