diff --git a/pkg/config/settings.go b/pkg/config/settings.go index 650cb055..e78ddd77 100644 --- a/pkg/config/settings.go +++ b/pkg/config/settings.go @@ -86,6 +86,8 @@ type InterfaceSettings struct { HostName string `koanf:"hostname,omitempty"` Domain string `koanf:"domain,omitempty"` + ExtraHosts map[string][]net.IPAddr `koanf:"extra_hosts,omitempty"` + MTU int `koanf:"mtu,omitempty"` DNS []net.IPAddr `koanf:"dns,omitempty"` Addresses []net.IPNet `koanf:"addresses,omitempty"` diff --git a/pkg/core/peer.go b/pkg/core/peer.go index a375d090..8636f91c 100644 --- a/pkg/core/peer.go +++ b/pkg/core/peer.go @@ -22,7 +22,8 @@ type SignalingState int type Peer struct { *wgtypes.Peer - Name string + Name string + Hosts map[string][]net.IP Interface *Interface diff --git a/pkg/daemon/feature/hsync/hsync.go b/pkg/daemon/feature/hsync/hsync.go index 1ae935c8..ea4fc7e2 100644 --- a/pkg/daemon/feature/hsync/hsync.go +++ b/pkg/daemon/feature/hsync/hsync.go @@ -3,6 +3,7 @@ package hsync import ( "fmt" + "net/netip" "strings" "github.com/stv0g/cunicu/pkg/daemon" @@ -56,35 +57,40 @@ func (hs *Interface) Close() error { } func (hs *Interface) Hosts() []Host { - hosts := []Host{} d := hs.Settings.Domain if d != "" && !strings.HasPrefix(d, ".") { d = "." + d } + hosts := []Host{} + for _, p := range hs.Peers { - pk := p.PublicKey() - // We use a shorted version of the public key as a DNS name here - pkName := pk.String()[:8] + m := map[netip.Addr][]string{} - for _, pfx := range hs.Settings.Prefixes { - addr := pk.IPAddress(pfx) + // Host names + for name, addrs := range p.Hosts { + for _, a := range addrs { + // TODO: validate that the addresses are covered by the peers AllowedIPs + addr, ok := netip.AddrFromSlice(a) + if !ok { + continue + } + m[addr] = append(m[addr], name+d) + } + } + + for addr, names := range m { h := Host{ - IP: addr.IP, + Names: names, + IP: addr.AsSlice(), Comment: fmt.Sprintf("%s: ifname=%s, ifindex=%d, pk=%s", hostsCommentPrefix, p.Interface.KernelDevice.Name(), p.Interface.KernelDevice.Index(), p.PublicKey()), } - if p.Name != "" { - h.Names = append(h.Names, p.Name+d) - } - - h.Names = append(h.Names, pkName+d) - hosts = append(hosts, h) } } diff --git a/pkg/daemon/feature/pdisc/handlers.go b/pkg/daemon/feature/pdisc/handlers.go index 219987f0..0c817755 100644 --- a/pkg/daemon/feature/pdisc/handlers.go +++ b/pkg/daemon/feature/pdisc/handlers.go @@ -2,6 +2,7 @@ package pdisc import ( "fmt" + "net" "time" "github.com/stv0g/cunicu/pkg/core" @@ -83,9 +84,7 @@ func (pd *Interface) OnPeerDescription(d *pdiscproto.PeerDescription) error { cfg := d.Config() - if d.Name != "" { - pd.peerNames[pk] = d.Name - } + pd.descs[pk] = d switch d.Change { case pdiscproto.PeerDescriptionChange_PEER_ADD: @@ -130,8 +129,21 @@ func (pd *Interface) OnPeerDescription(d *pdiscproto.PeerDescription) error { } func (pd *Interface) OnPeerAdded(p *core.Peer) { - if name, ok := pd.peerNames[p.PublicKey()]; ok { - p.Name = name + if d, ok := pd.descs[p.PublicKey()]; ok { + p.Name = d.Name + + if hosts := d.Hosts; len(hosts) > 0 { + p.Hosts = map[string][]net.IP{} + + for name, addrs := range hosts { + hs := []net.IP{} + for _, addr := range addrs.Addresses { + hs = append(hs, addr.Address()) + } + + p.Hosts[name] = hs + } + } } } diff --git a/pkg/daemon/feature/pdisc/pdisc.go b/pkg/daemon/feature/pdisc/pdisc.go index c049a9ad..65b31dde 100644 --- a/pkg/daemon/feature/pdisc/pdisc.go +++ b/pkg/daemon/feature/pdisc/pdisc.go @@ -14,6 +14,7 @@ import ( "github.com/stv0g/cunicu/pkg/util" "github.com/stv0g/cunicu/pkg/util/buildinfo" + proto "github.com/stv0g/cunicu/pkg/proto/core" pdiscproto "github.com/stv0g/cunicu/pkg/proto/feature/pdisc" ) @@ -28,8 +29,8 @@ func init() { type Interface struct { *daemon.Interface - peerFilter map[crypto.Key]bool - peerNames map[crypto.Key]string + filter map[crypto.Key]bool + descs map[crypto.Key]*pdiscproto.PeerDescription logger *zap.Logger } @@ -40,18 +41,18 @@ func New(i *daemon.Interface) (daemon.Feature, error) { } pd := &Interface{ - Interface: i, - peerFilter: map[crypto.Key]bool{}, - peerNames: map[crypto.Key]string{}, - logger: zap.L().Named("pdisc").With(zap.String("intf", i.Name())), + Interface: i, + filter: map[crypto.Key]bool{}, + descs: map[crypto.Key]*pdiscproto.PeerDescription{}, + logger: zap.L().Named("pdisc").With(zap.String("intf", i.Name())), } for _, k := range pd.Settings.Whitelist { - pd.peerFilter[crypto.Key(k)] = true + pd.filter[crypto.Key(k)] = true } for _, k := range pd.Settings.Blacklist { - pd.peerFilter[crypto.Key(k)] = false + pd.filter[crypto.Key(k)] = false } // Avoid sending a peer description if the interface does not have a private key yet @@ -123,6 +124,34 @@ func (pd *Interface) sendPeerDescription(chg pdiscproto.PeerDescriptionChange, p Name: pd.Settings.HostName, AllowedIps: util.SliceString(allowedIPs), BuildInfo: buildinfo.BuildInfo(), + Hosts: map[string]*pdiscproto.PeerAddresses{}, + } + + if extraHosts := pd.Settings.ExtraHosts; len(extraHosts) > 0 { + for name, addrs := range extraHosts { + daddrs := []*proto.IPAddress{} + + for _, addr := range addrs { + daddr := proto.Address(addr.IP) + daddrs = append(daddrs, daddr) + } + + d.Hosts[name] = &pdiscproto.PeerAddresses{ + Addresses: daddrs, + } + } + } + + if pd.Settings.HostName != "" { + daddrs := []*proto.IPAddress{} + for _, pfx := range pd.Settings.Prefixes { + addr := pk.IPAddress(pfx) + daddrs = append(daddrs, proto.Address(addr.IP)) + } + + d.Hosts[pd.Settings.HostName] = &pdiscproto.PeerAddresses{ + Addresses: daddrs, + } } if pkOld != nil { @@ -155,7 +184,7 @@ func (pd *Interface) sendPeerDescription(chg pdiscproto.PeerDescriptionChange, p } func (pd *Interface) isAccepted(pk crypto.Key) bool { - if verdict, ok := pd.peerFilter[pk]; ok { + if verdict, ok := pd.filter[pk]; ok { return verdict } diff --git a/pkg/proto/core/net.go b/pkg/proto/core/net.go new file mode 100644 index 00000000..91adc476 --- /dev/null +++ b/pkg/proto/core/net.go @@ -0,0 +1,36 @@ +package core + +import "net" + +func Address(i net.IP) *IPAddress { + if b := i.To4(); b != nil { + i = b + } + + return &IPAddress{ + Addr: i, + } +} + +func (i *IPAddress) Address() net.IP { + return (net.IP)(i.Addr) +} + +func Prefix(i net.IPNet) *IPPrefix { + ones, _ := i.Mask.Size() + + return &IPPrefix{ + Addr: i.IP, + Pfxlen: uint32(ones), + } +} + +func (i *IPPrefix) Prefix() *net.IPNet { + ones := int(i.Pfxlen) + bits := len(i.Addr) * 8 + + return &net.IPNet{ + IP: i.Addr, + Mask: net.CIDRMask(ones, bits), + } +} diff --git a/pkg/proto/core/net.pb.go b/pkg/proto/core/net.pb.go new file mode 100644 index 00000000..35598f66 --- /dev/null +++ b/pkg/proto/core/net.pb.go @@ -0,0 +1,215 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.6.1 +// source: core/net.proto + +package core + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type IPAddress struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` +} + +func (x *IPAddress) Reset() { + *x = IPAddress{} + if protoimpl.UnsafeEnabled { + mi := &file_core_net_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IPAddress) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IPAddress) ProtoMessage() {} + +func (x *IPAddress) ProtoReflect() protoreflect.Message { + mi := &file_core_net_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IPAddress.ProtoReflect.Descriptor instead. +func (*IPAddress) Descriptor() ([]byte, []int) { + return file_core_net_proto_rawDescGZIP(), []int{0} +} + +func (x *IPAddress) GetAddr() []byte { + if x != nil { + return x.Addr + } + return nil +} + +type IPPrefix struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` + Pfxlen uint32 `protobuf:"varint,2,opt,name=pfxlen,proto3" json:"pfxlen,omitempty"` +} + +func (x *IPPrefix) Reset() { + *x = IPPrefix{} + if protoimpl.UnsafeEnabled { + mi := &file_core_net_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IPPrefix) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IPPrefix) ProtoMessage() {} + +func (x *IPPrefix) ProtoReflect() protoreflect.Message { + mi := &file_core_net_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IPPrefix.ProtoReflect.Descriptor instead. +func (*IPPrefix) Descriptor() ([]byte, []int) { + return file_core_net_proto_rawDescGZIP(), []int{1} +} + +func (x *IPPrefix) GetAddr() []byte { + if x != nil { + return x.Addr + } + return nil +} + +func (x *IPPrefix) GetPfxlen() uint32 { + if x != nil { + return x.Pfxlen + } + return 0 +} + +var File_core_net_proto protoreflect.FileDescriptor + +var file_core_net_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x6e, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x0b, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x22, 0x1f, 0x0a, + 0x09, 0x49, 0x50, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, + 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x22, 0x36, + 0x0a, 0x08, 0x49, 0x50, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, + 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x16, + 0x0a, 0x06, 0x70, 0x66, 0x78, 0x6c, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, + 0x70, 0x66, 0x78, 0x6c, 0x65, 0x6e, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x76, 0x30, 0x67, 0x2f, 0x63, 0x75, 0x6e, 0x69, 0x63, + 0x75, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x72, 0x65, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_core_net_proto_rawDescOnce sync.Once + file_core_net_proto_rawDescData = file_core_net_proto_rawDesc +) + +func file_core_net_proto_rawDescGZIP() []byte { + file_core_net_proto_rawDescOnce.Do(func() { + file_core_net_proto_rawDescData = protoimpl.X.CompressGZIP(file_core_net_proto_rawDescData) + }) + return file_core_net_proto_rawDescData +} + +var file_core_net_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_core_net_proto_goTypes = []interface{}{ + (*IPAddress)(nil), // 0: cunicu.core.IPAddress + (*IPPrefix)(nil), // 1: cunicu.core.IPPrefix +} +var file_core_net_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_core_net_proto_init() } +func file_core_net_proto_init() { + if File_core_net_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_core_net_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IPAddress); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_core_net_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IPPrefix); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_core_net_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_core_net_proto_goTypes, + DependencyIndexes: file_core_net_proto_depIdxs, + MessageInfos: file_core_net_proto_msgTypes, + }.Build() + File_core_net_proto = out.File + file_core_net_proto_rawDesc = nil + file_core_net_proto_goTypes = nil + file_core_net_proto_depIdxs = nil +} diff --git a/pkg/proto/feature/pdisc/pdisc.pb.go b/pkg/proto/feature/pdisc/pdisc.pb.go index d0a3fd64..985d8b38 100644 --- a/pkg/proto/feature/pdisc/pdisc.pb.go +++ b/pkg/proto/feature/pdisc/pdisc.pb.go @@ -8,6 +8,7 @@ package pdisc import ( proto "github.com/stv0g/cunicu/pkg/proto" + core "github.com/stv0g/cunicu/pkg/proto/core" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -70,6 +71,53 @@ func (PeerDescriptionChange) EnumDescriptor() ([]byte, []int) { return file_feature_pdisc_proto_rawDescGZIP(), []int{0} } +type PeerAddresses struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Addresses []*core.IPAddress `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"` +} + +func (x *PeerAddresses) Reset() { + *x = PeerAddresses{} + if protoimpl.UnsafeEnabled { + mi := &file_feature_pdisc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PeerAddresses) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PeerAddresses) ProtoMessage() {} + +func (x *PeerAddresses) ProtoReflect() protoreflect.Message { + mi := &file_feature_pdisc_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PeerAddresses.ProtoReflect.Descriptor instead. +func (*PeerAddresses) Descriptor() ([]byte, []int) { + return file_feature_pdisc_proto_rawDescGZIP(), []int{0} +} + +func (x *PeerAddresses) GetAddresses() []*core.IPAddress { + if x != nil { + return x.Addresses + } + return nil +} + // A PeerDescription is an announcement of a peer which is distributed to type PeerDescription struct { state protoimpl.MessageState @@ -88,12 +136,14 @@ type PeerDescription struct { AllowedIps []string `protobuf:"bytes,5,rep,name=allowed_ips,json=allowedIps,proto3" json:"allowed_ips,omitempty"` // cunicu build information BuildInfo *proto.BuildInfo `protobuf:"bytes,6,opt,name=build_info,json=buildInfo,proto3" json:"build_info,omitempty"` + // IP to Hostname mapping + Hosts map[string]*PeerAddresses `protobuf:"bytes,7,rep,name=hosts,proto3" json:"hosts,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *PeerDescription) Reset() { *x = PeerDescription{} if protoimpl.UnsafeEnabled { - mi := &file_feature_pdisc_proto_msgTypes[0] + mi := &file_feature_pdisc_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -106,7 +156,7 @@ func (x *PeerDescription) String() string { func (*PeerDescription) ProtoMessage() {} func (x *PeerDescription) ProtoReflect() protoreflect.Message { - mi := &file_feature_pdisc_proto_msgTypes[0] + mi := &file_feature_pdisc_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -119,7 +169,7 @@ func (x *PeerDescription) ProtoReflect() protoreflect.Message { // Deprecated: Use PeerDescription.ProtoReflect.Descriptor instead. func (*PeerDescription) Descriptor() ([]byte, []int) { - return file_feature_pdisc_proto_rawDescGZIP(), []int{0} + return file_feature_pdisc_proto_rawDescGZIP(), []int{1} } func (x *PeerDescription) GetChange() PeerDescriptionChange { @@ -164,37 +214,58 @@ func (x *PeerDescription) GetBuildInfo() *proto.BuildInfo { return nil } +func (x *PeerDescription) GetHosts() map[string]*PeerAddresses { + if x != nil { + return x.Hosts + } + return nil +} + var File_feature_pdisc_proto protoreflect.FileDescriptor var file_feature_pdisc_proto_rawDesc = []byte{ 0x0a, 0x13, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x2f, 0x70, 0x64, 0x69, 0x73, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x70, 0x64, 0x69, 0x73, 0x63, 0x1a, 0x0c, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0xfa, 0x01, 0x0a, 0x0f, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x06, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x70, - 0x64, 0x69, 0x73, 0x63, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x06, 0x63, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, - 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, - 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12, 0x24, 0x0a, 0x0e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, - 0x6b, 0x65, 0x79, 0x5f, 0x6e, 0x65, 0x77, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x4e, 0x65, 0x77, 0x12, 0x1f, 0x0a, 0x0b, 0x61, - 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x49, 0x70, 0x73, 0x12, 0x30, 0x0a, 0x0a, - 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x11, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, - 0x6e, 0x66, 0x6f, 0x52, 0x09, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x2a, 0x47, - 0x0a, 0x15, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, - 0x41, 0x44, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x52, 0x45, - 0x4d, 0x4f, 0x56, 0x45, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x55, - 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x02, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x76, 0x30, 0x67, 0x2f, 0x63, 0x75, 0x6e, 0x69, - 0x63, 0x75, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x65, 0x61, - 0x74, 0x75, 0x72, 0x65, 0x2f, 0x70, 0x64, 0x69, 0x73, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x6f, 0x1a, 0x0e, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x6e, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x45, 0x0a, 0x0d, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x65, 0x73, 0x12, 0x34, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x50, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x09, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x22, 0x91, 0x03, 0x0a, 0x0f, 0x50, 0x65, 0x65, + 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x06, + 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x63, + 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x70, 0x64, 0x69, 0x73, 0x63, 0x2e, 0x50, 0x65, 0x65, 0x72, + 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x52, 0x06, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, + 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12, 0x24, 0x0a, 0x0e, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x6e, 0x65, 0x77, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x4e, + 0x65, 0x77, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x69, 0x70, + 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, + 0x49, 0x70, 0x73, 0x12, 0x30, 0x0a, 0x0a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x6e, 0x66, + 0x6f, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, + 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x09, 0x62, 0x75, 0x69, 0x6c, + 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x3e, 0x0a, 0x05, 0x68, 0x6f, 0x73, 0x74, 0x73, 0x18, 0x07, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x70, 0x64, + 0x69, 0x73, 0x63, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x2e, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, + 0x68, 0x6f, 0x73, 0x74, 0x73, 0x1a, 0x55, 0x0a, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x70, 0x64, + 0x69, 0x73, 0x63, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, + 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x47, 0x0a, 0x15, + 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41, 0x44, + 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x52, 0x45, 0x4d, 0x4f, + 0x56, 0x45, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x55, 0x50, 0x44, + 0x41, 0x54, 0x45, 0x10, 0x02, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x76, 0x30, 0x67, 0x2f, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, + 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x65, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x2f, 0x70, 0x64, 0x69, 0x73, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -210,20 +281,26 @@ func file_feature_pdisc_proto_rawDescGZIP() []byte { } var file_feature_pdisc_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_feature_pdisc_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_feature_pdisc_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_feature_pdisc_proto_goTypes = []interface{}{ (PeerDescriptionChange)(0), // 0: cunicu.pdisc.PeerDescriptionChange - (*PeerDescription)(nil), // 1: cunicu.pdisc.PeerDescription - (*proto.BuildInfo)(nil), // 2: cunicu.BuildInfo + (*PeerAddresses)(nil), // 1: cunicu.pdisc.PeerAddresses + (*PeerDescription)(nil), // 2: cunicu.pdisc.PeerDescription + nil, // 3: cunicu.pdisc.PeerDescription.HostsEntry + (*core.IPAddress)(nil), // 4: cunicu.core.IPAddress + (*proto.BuildInfo)(nil), // 5: cunicu.BuildInfo } var file_feature_pdisc_proto_depIdxs = []int32{ - 0, // 0: cunicu.pdisc.PeerDescription.change:type_name -> cunicu.pdisc.PeerDescriptionChange - 2, // 1: cunicu.pdisc.PeerDescription.build_info:type_name -> cunicu.BuildInfo - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 4, // 0: cunicu.pdisc.PeerAddresses.addresses:type_name -> cunicu.core.IPAddress + 0, // 1: cunicu.pdisc.PeerDescription.change:type_name -> cunicu.pdisc.PeerDescriptionChange + 5, // 2: cunicu.pdisc.PeerDescription.build_info:type_name -> cunicu.BuildInfo + 3, // 3: cunicu.pdisc.PeerDescription.hosts:type_name -> cunicu.pdisc.PeerDescription.HostsEntry + 1, // 4: cunicu.pdisc.PeerDescription.HostsEntry.value:type_name -> cunicu.pdisc.PeerAddresses + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_feature_pdisc_proto_init() } @@ -233,6 +310,18 @@ func file_feature_pdisc_proto_init() { } if !protoimpl.UnsafeEnabled { file_feature_pdisc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PeerAddresses); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_feature_pdisc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PeerDescription); i { case 0: return &v.state @@ -251,7 +340,7 @@ func file_feature_pdisc_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_feature_pdisc_proto_rawDesc, NumEnums: 1, - NumMessages: 1, + NumMessages: 3, NumExtensions: 0, NumServices: 0, }, diff --git a/pkg/proto/proto.go b/pkg/proto/proto.go index 76a3ba7c..59f96bee 100644 --- a/pkg/proto/proto.go +++ b/pkg/proto/proto.go @@ -2,7 +2,7 @@ package proto //go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto common.proto -//go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto core/peer.proto core/interface.proto +//go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto core/peer.proto core/interface.proto core/net.proto //go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto signaling/signaling.proto signaling/relay.proto //go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto rpc/daemon.proto rpc/epdisc.proto rpc/event.proto rpc/signaling.proto rpc/invitation.proto //go:generate protoc --proto_path=../../proto --go_out=. --go_opt=paths=import,module=github.com/stv0g/cunicu/pkg/proto feature/epdisc.proto feature/epdisc_candidate.proto feature/pdisc.proto feature/pske.proto feature/hooks.proto diff --git a/proto/core/net.proto b/proto/core/net.proto new file mode 100644 index 00000000..8a5807e5 --- /dev/null +++ b/proto/core/net.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package cunicu.core; +option go_package = "github.com/stv0g/cunicu/pkg/proto/core"; + +message IPAddress { + bytes addr = 1; +} + +message IPPrefix { + bytes addr = 1; + uint32 pfxlen = 2; +} \ No newline at end of file diff --git a/proto/feature/pdisc.proto b/proto/feature/pdisc.proto index 4196d76d..acb4c567 100644 --- a/proto/feature/pdisc.proto +++ b/proto/feature/pdisc.proto @@ -4,6 +4,7 @@ package cunicu.pdisc; option go_package = "github.com/stv0g/cunicu/pkg/proto/feature/pdisc"; import "common.proto"; +import "core/net.proto"; enum PeerDescriptionChange { PEER_ADD = 0; @@ -11,6 +12,10 @@ enum PeerDescriptionChange { PEER_UPDATE = 2; } +message PeerAddresses { + repeated core.IPAddress addresses = 1; +} + // A PeerDescription is an announcement of a peer which is distributed to message PeerDescription { PeerDescriptionChange change = 1; @@ -30,4 +35,7 @@ message PeerDescription { // cunicu build information BuildInfo build_info = 6; + + // IP to Hostname mapping + map hosts = 7; }