implement RPC data for LuxOptionNetIf, various bug fixes
This commit is contained in:
parent
d5860973bf
commit
854ae81ddb
4 changed files with 67 additions and 4 deletions
|
|
@ -1,10 +1,10 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lux/proto"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -24,6 +24,21 @@ const (
|
|||
LuxNetAddrType6GUA = 3
|
||||
)
|
||||
|
||||
func (addrType LuxNetAddrType) String() string {
|
||||
switch addrType {
|
||||
case LuxNetAddrType4:
|
||||
return "ip4"
|
||||
case LuxNetAddrType6LL:
|
||||
return "ip6ll"
|
||||
case LuxNetAddrType6ULA:
|
||||
return "ip6ula"
|
||||
case LuxNetAddrType6GUA:
|
||||
return "ip6gua"
|
||||
default:
|
||||
return strconv.Itoa(int(addrType))
|
||||
}
|
||||
}
|
||||
|
||||
type LuxNetAddr struct {
|
||||
Type LuxNetAddrType
|
||||
Addr netip.Addr
|
||||
|
|
@ -179,7 +194,6 @@ func (opt *LuxOptionNetIf) EnumerateNetlink() error {
|
|||
if len(netif.Addrs) > 0 {
|
||||
// only add if we got atleast 1 ip, since we might want to skip
|
||||
// netif loopback that has no IP because we skip one in FromNetlink
|
||||
fmt.Println(netif)
|
||||
opt.Interfaces[netif.Name] = &netif
|
||||
}
|
||||
}
|
||||
|
|
@ -198,6 +212,8 @@ func (opt *LuxOptionNetIf) Read(rd *proto.LuxBuffer) error {
|
|||
if err := netif.Read(rd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opt.Interfaces[netif.Name] = &netif
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -66,7 +66,26 @@ func (state *LuxState) IntoRpc() rpc.LuxRpcState {
|
|||
wan := opt.(*LuxOptionWAN)
|
||||
rpcState.WAN = rpc.LuxRpcWAN{
|
||||
Addr4: wan.Addr4.String(),
|
||||
Addr6: wan.Addr4.String(),
|
||||
Addr6: wan.Addr6.String(),
|
||||
}
|
||||
case LuxOptionTypeNetIf:
|
||||
netif := opt.(*LuxOptionNetIf)
|
||||
|
||||
rpcState.NetIf.Interfaces = make([]rpc.LuxRpcNetInterface, 0)
|
||||
for _, optIf := range netif.Interfaces {
|
||||
rpcIf := rpc.LuxRpcNetInterface{
|
||||
Name: optIf.Name,
|
||||
Index: optIf.Index,
|
||||
Addrs: make([]rpc.LuxRpcNetAddr, 0),
|
||||
}
|
||||
for _, optAddr := range optIf.Addrs {
|
||||
rpcIf.Addrs = append(rpcIf.Addrs, rpc.LuxRpcNetAddr{
|
||||
Type: optAddr.Type.String(),
|
||||
Addr: optAddr.Addr.String(),
|
||||
})
|
||||
}
|
||||
|
||||
rpcState.NetIf.Interfaces = append(rpcState.NetIf.Interfaces, rpcIf)
|
||||
}
|
||||
default:
|
||||
// encode option in base64 blob
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -828,6 +828,12 @@ func rpcMain() {
|
|||
|
||||
fmt.Printf("host %s hostname %s\n", host.HostID, host.Hostname)
|
||||
fmt.Printf("wan addr4 %s addr6 %s\n", host.State.WAN.Addr4, host.State.WAN.Addr6)
|
||||
for _, netif := range host.State.NetIf.Interfaces {
|
||||
fmt.Printf("netif %s idx %d\n", netif.Name, netif.Index)
|
||||
for _, addr := range netif.Addrs {
|
||||
fmt.Printf("\t%s\t%s\n", addr.Type, addr.Addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,32 @@ type LuxRpcOption struct {
|
|||
Blob string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type LuxRpcNetAddr struct {
|
||||
XMLName xml.Name `xml:"addr"`
|
||||
Type string `xml:"type,attr"`
|
||||
Addr string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type LuxRpcNetInterface struct {
|
||||
XMLName xml.Name `xml:"if"`
|
||||
|
||||
Name string `xml:"name,attr"`
|
||||
Index int `xml:"idx,attr"`
|
||||
|
||||
Addrs []LuxRpcNetAddr `xml:"addr"`
|
||||
}
|
||||
|
||||
type LuxRpcNetIf struct {
|
||||
XMLName xml.Name `xml:"netif"`
|
||||
|
||||
Interfaces []LuxRpcNetInterface `xml:"if"`
|
||||
}
|
||||
|
||||
type LuxRpcState struct {
|
||||
XMLName xml.Name `xml:"state"`
|
||||
|
||||
WAN LuxRpcWAN `xml:"wan"`
|
||||
NetIf LuxRpcNetIf `xml:"netif"`
|
||||
|
||||
Options []LuxRpcOption `xml:"option"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue