diff --git a/pkg/machinery/go.mod b/pkg/machinery/go.mod index a7f368e62..dae3b6721 100644 --- a/pkg/machinery/go.mod +++ b/pkg/machinery/go.mod @@ -23,7 +23,6 @@ require ( github.com/talos-systems/go-blockdevice v0.2.4 github.com/talos-systems/go-debug v0.2.1 github.com/talos-systems/net v0.3.0 - golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 google.golang.org/genproto v0.0.0-20211021150943-2b146023228c google.golang.org/grpc v1.41.0 google.golang.org/protobuf v1.27.1 @@ -44,6 +43,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect + golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect golang.org/x/text v0.3.6 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/pkg/machinery/nethelpers/address_flags.go b/pkg/machinery/nethelpers/address_flags.go new file mode 100644 index 000000000..0729452e3 --- /dev/null +++ b/pkg/machinery/nethelpers/address_flags.go @@ -0,0 +1,50 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package nethelpers + +//go:generate stringer -type=AddressFlag -linecomment + +import ( + "strings" +) + +// AddressFlags is a bitmask of AddressFlag. +type AddressFlags uint32 + +func (flags AddressFlags) String() string { + var values []string + + for flag := AddressTemporary; flag <= AddressStablePrivacy; flag <<= 1 { + if (AddressFlag(flags) & flag) == flag { + values = append(values, flag.String()) + } + } + + return strings.Join(values, ",") +} + +// MarshalYAML implements yaml.Marshaler. +func (flags AddressFlags) MarshalYAML() (interface{}, error) { + return flags.String(), nil +} + +// AddressFlag wraps IFF_* constants. +type AddressFlag uint32 + +// AddressFlag constants. +const ( + AddressTemporary AddressFlag = 1 << iota // temporary + AddressNoDAD // nodad + AddressOptimistic // optimistic + AddressDADFailed // dadfailed + AddressHome // homeaddress + AddressDeprecated // deprecated + AddressTentative // tentative + AddressPermanent // permanent + AddressManagementTemp // mngmtmpaddr + AddressNoPrefixRoute // noprefixroute + AddressMCAutoJoin // mcautojoin + AddressStablePrivacy // stableprivacy +) diff --git a/pkg/machinery/nethelpers/address_flags_linux.go b/pkg/machinery/nethelpers/address_flags_linux.go deleted file mode 100644 index d618bd92d..000000000 --- a/pkg/machinery/nethelpers/address_flags_linux.go +++ /dev/null @@ -1,52 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -package nethelpers - -//go:generate stringer -type=AddressFlag -linecomment -output addressflag_string_linux.go - -import ( - "strings" - - "golang.org/x/sys/unix" -) - -// AddressFlags is a bitmask of AddressFlag. -type AddressFlags uint32 - -func (flags AddressFlags) String() string { - var values []string - - for flag := AddressTemporary; flag <= AddressStablePrivacy; flag <<= 1 { - if (AddressFlag(flags) & flag) == flag { - values = append(values, flag.String()) - } - } - - return strings.Join(values, ",") -} - -// MarshalYAML implements yaml.Marshaler. -func (flags AddressFlags) MarshalYAML() (interface{}, error) { - return flags.String(), nil -} - -// AddressFlag wraps IFF_* constants. -type AddressFlag uint32 - -// AddressFlag constants. -const ( - AddressTemporary AddressFlag = unix.IFA_F_TEMPORARY // temporary - AddressNoDAD AddressFlag = unix.IFA_F_NODAD // nodad - AddressOptimistic AddressFlag = unix.IFA_F_OPTIMISTIC // optimistic - AddressDADFailed AddressFlag = unix.IFA_F_DADFAILED // dadfailed - AddressHome AddressFlag = unix.IFA_F_HOMEADDRESS // homeaddress - AddressDeprecated AddressFlag = unix.IFA_F_DEPRECATED // deprecated - AddressTentative AddressFlag = unix.IFA_F_TENTATIVE // tentative - AddressPermanent AddressFlag = unix.IFA_F_PERMANENT // permanent - AddressManagementTemp AddressFlag = unix.IFA_F_MANAGETEMPADDR // mngmtmpaddr - AddressNoPrefixRoute AddressFlag = unix.IFA_F_NOPREFIXROUTE // noprefixroute - AddressMCAutoJoin AddressFlag = unix.IFA_F_MCAUTOJOIN // mcautojoin - AddressStablePrivacy AddressFlag = unix.IFA_F_STABLE_PRIVACY // stableprivacy -) diff --git a/pkg/machinery/nethelpers/addressflag_string_linux.go b/pkg/machinery/nethelpers/addressflag_string.go similarity index 92% rename from pkg/machinery/nethelpers/addressflag_string_linux.go rename to pkg/machinery/nethelpers/addressflag_string.go index 9ea145518..5c982e8f0 100644 --- a/pkg/machinery/nethelpers/addressflag_string_linux.go +++ b/pkg/machinery/nethelpers/addressflag_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=AddressFlag -linecomment -output addressflag_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=AddressFlag -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/family_linux.go b/pkg/machinery/nethelpers/family.go similarity index 68% rename from pkg/machinery/nethelpers/family_linux.go rename to pkg/machinery/nethelpers/family.go index 3a203e4e0..64c37900e 100644 --- a/pkg/machinery/nethelpers/family_linux.go +++ b/pkg/machinery/nethelpers/family.go @@ -4,9 +4,7 @@ package nethelpers -import "golang.org/x/sys/unix" - -//go:generate stringer -type=Family -linecomment -output family_string_linux.go +//go:generate stringer -type=Family -linecomment // Family is a network family. type Family uint8 @@ -18,6 +16,6 @@ func (family Family) MarshalYAML() (interface{}, error) { // Family constants. const ( - FamilyInet4 Family = unix.AF_INET // inet4 - FamilyInet6 Family = unix.AF_INET6 // inet6 + FamilyInet4 Family = 2 // inet4 + FamilyInet6 Family = 10 // inet6 ) diff --git a/pkg/machinery/nethelpers/family_string_linux.go b/pkg/machinery/nethelpers/family_string.go similarity index 83% rename from pkg/machinery/nethelpers/family_string_linux.go rename to pkg/machinery/nethelpers/family_string.go index 7a5ff0e69..979544fac 100644 --- a/pkg/machinery/nethelpers/family_string_linux.go +++ b/pkg/machinery/nethelpers/family_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=Family -linecomment -output family_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=Family -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/linkflag.go b/pkg/machinery/nethelpers/linkflag.go new file mode 100644 index 000000000..46d0b9602 --- /dev/null +++ b/pkg/machinery/nethelpers/linkflag.go @@ -0,0 +1,57 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package nethelpers + +//go:generate stringer -type=LinkFlag -linecomment + +import ( + "strings" +) + +// LinkFlags is a bitmask of LinkFlags. +type LinkFlags uint32 + +func (flags LinkFlags) String() string { + var values []string + + for flag := LinkUp; flag <= LinkEcho; flag <<= 1 { + if (LinkFlag(flags) & flag) == flag { + values = append(values, flag.String()) + } + } + + return strings.Join(values, ",") +} + +// MarshalYAML implements yaml.Marshaler. +func (flags LinkFlags) MarshalYAML() (interface{}, error) { + return flags.String(), nil +} + +// LinkFlag wraps IFF_* constants. +type LinkFlag uint32 + +// LinkFlag constants. +const ( + LinkUp LinkFlag = 1 << iota // UP + LinkBroadcast // BROADCAST + LinkDebug // DEBUG + LinkLoopback // LOOPBACK + LinkPointToPoint // POINTTOPOINT + LinkNoTrailers // NOTRAILERS + LinkRunning // RUNNING + LinkNoArp // NOARP + LinkPromisc // PROMISC + LinkAllMulti // ALLMULTI + LinkMaster // MASTER + LinkSlave // SLAVE + LinkMulticase // MULTICAST + LinkPortsel // PORTSEL + LinKAutoMedia // AUTOMEDIA + LinkDynamic // DYNAMIC + LinkLowerUp // LOWER_UP + LinkDormant // DORMANT + LinkEcho // ECHO +) diff --git a/pkg/machinery/nethelpers/linkflag_linux.go b/pkg/machinery/nethelpers/linkflag_linux.go deleted file mode 100644 index bd9a2a943..000000000 --- a/pkg/machinery/nethelpers/linkflag_linux.go +++ /dev/null @@ -1,59 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -package nethelpers - -//go:generate stringer -type=LinkFlag -linecomment -output linkflag_string_linux.go - -import ( - "strings" - - "golang.org/x/sys/unix" -) - -// LinkFlags is a bitmask of LinkFlags. -type LinkFlags uint32 - -func (flags LinkFlags) String() string { - var values []string - - for flag := LinkUp; flag <= LinkEcho; flag <<= 1 { - if (LinkFlag(flags) & flag) == flag { - values = append(values, flag.String()) - } - } - - return strings.Join(values, ",") -} - -// MarshalYAML implements yaml.Marshaler. -func (flags LinkFlags) MarshalYAML() (interface{}, error) { - return flags.String(), nil -} - -// LinkFlag wraps IFF_* constants. -type LinkFlag uint32 - -// LinkFlag constants. -const ( - LinkUp LinkFlag = unix.IFF_UP // UP - LinkBroadcast LinkFlag = unix.IFF_BROADCAST // BROADCAST - LinkDebug LinkFlag = unix.IFF_DEBUG // DEBUG - LinkLoopback LinkFlag = unix.IFF_LOOPBACK // LOOPBACK - LinkPointToPoint LinkFlag = unix.IFF_POINTOPOINT // POINTTOPOINT - LinkRunning LinkFlag = unix.IFF_RUNNING // RUNNING - LinkNoArp LinkFlag = unix.IFF_NOARP // NOARP - LinkPromisc LinkFlag = unix.IFF_PROMISC // PROMISC - LinkNoTrailers LinkFlag = unix.IFF_NOTRAILERS // NOTRAILERS - LinkAllMulti LinkFlag = unix.IFF_ALLMULTI // ALLMULTI - LinkMaster LinkFlag = unix.IFF_MASTER // MASTER - LinkSlave LinkFlag = unix.IFF_SLAVE // SLAVE - LinkMulticase LinkFlag = unix.IFF_MULTICAST // MULTICAST - LinkPortsel LinkFlag = unix.IFF_PORTSEL // PORTSEL - LinKAutoMedia LinkFlag = unix.IFF_AUTOMEDIA // AUTOMEDIA - LinkDynamic LinkFlag = unix.IFF_DYNAMIC // DYNAMIC - LinkLowerUp LinkFlag = unix.IFF_LOWER_UP // LOWER_UP - LinkDormant LinkFlag = unix.IFF_DORMANT // DORMANT - LinkEcho LinkFlag = unix.IFF_ECHO // ECHO -) diff --git a/pkg/machinery/nethelpers/linkflag_string_linux.go b/pkg/machinery/nethelpers/linkflag_string.go similarity index 93% rename from pkg/machinery/nethelpers/linkflag_string_linux.go rename to pkg/machinery/nethelpers/linkflag_string.go index f4bfdd65f..48fb6974f 100644 --- a/pkg/machinery/nethelpers/linkflag_string_linux.go +++ b/pkg/machinery/nethelpers/linkflag_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=LinkFlag -linecomment -output linkflag_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=LinkFlag -linecomment"; DO NOT EDIT. package nethelpers @@ -13,10 +13,10 @@ func _() { _ = x[LinkDebug-4] _ = x[LinkLoopback-8] _ = x[LinkPointToPoint-16] + _ = x[LinkNoTrailers-32] _ = x[LinkRunning-64] _ = x[LinkNoArp-128] _ = x[LinkPromisc-256] - _ = x[LinkNoTrailers-32] _ = x[LinkAllMulti-512] _ = x[LinkMaster-1024] _ = x[LinkSlave-2048] diff --git a/pkg/machinery/nethelpers/linktype.go b/pkg/machinery/nethelpers/linktype.go new file mode 100644 index 000000000..dd3f454ed --- /dev/null +++ b/pkg/machinery/nethelpers/linktype.go @@ -0,0 +1,96 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package nethelpers + +//go:generate stringer -type=LinkType -linecomment + +// LinkType is a link type. +type LinkType uint16 + +// MarshalYAML implements yaml.Marshaler. +func (typ LinkType) MarshalYAML() (interface{}, error) { + return typ.String(), nil +} + +// LinkType constants. +const ( + LinkNetrom LinkType = 0 // netrom + LinkEther LinkType = 1 // ether + LinkEether LinkType = 2 // eether + LinkAx25 LinkType = 3 // ax25 + LinkPronet LinkType = 4 // pronet + LinkChaos LinkType = 5 // chaos + LinkIee802 LinkType = 6 // ieee802 + LinkArcnet LinkType = 7 // arcnet + LinkAtalk LinkType = 8 // atalk + LinkDlci LinkType = 15 // dlci + LinkAtm LinkType = 19 // atm + LinkMetricom LinkType = 23 // metricom + LinkIeee1394 LinkType = 24 // ieee1394 + LinkEui64 LinkType = 27 // eui64 + LinkInfiniband LinkType = 32 // infiniband + LinkSlip LinkType = 256 // slip + LinkCslip LinkType = 257 // cslip + LinkSlip6 LinkType = 258 // slip6 + LinkCslip6 LinkType = 259 // cslip6 + LinkRsrvd LinkType = 260 // rsrvd + LinkAdapt LinkType = 264 // adapt + LinkRose LinkType = 270 // rose + LinkX25 LinkType = 271 // x25 + LinkHwx25 LinkType = 272 // hwx25 + LinkCan LinkType = 280 // can + LinkPpp LinkType = 512 // ppp + LinkCisco LinkType = 513 // cisco + LinkHdlc LinkType = 513 // hdlc + LinkLapb LinkType = 516 // lapb + LinkDdcmp LinkType = 517 // ddcmp + LinkRawhdlc LinkType = 518 // rawhdlc + LinkTunnel LinkType = 768 // ipip + LinkTunnel6 LinkType = 769 // tunnel6 + LinkFrad LinkType = 770 // frad + LinkSkip LinkType = 771 // skip + LinkLoopbck LinkType = 772 // loopback + LinkLocaltlk LinkType = 773 // localtlk + LinkFddi LinkType = 774 // fddi + LinkBif LinkType = 775 // bif + LinkSit LinkType = 776 // sit + LinkIpddp LinkType = 777 // ip/ddp + LinkIpgre LinkType = 778 // gre + LinkPimreg LinkType = 779 // pimreg + LinkHippi LinkType = 780 // hippi + LinkAsh LinkType = 781 // ash + LinkEconet LinkType = 782 // econet + LinkIrda LinkType = 783 // irda + LinkFcpp LinkType = 784 // fcpp + LinkFcal LinkType = 785 // fcal + LinkFcpl LinkType = 786 // fcpl + LinkFcfabric LinkType = 787 // fcfb_0 + LinkFcfabric1 LinkType = LinkFcfabric + 1 // fcfb_1 + LinkFcfabric2 LinkType = LinkFcfabric + 2 // fcfb_2 + LinkFcfabric3 LinkType = LinkFcfabric + 3 // fcfb_3 + LinkFcfabric4 LinkType = LinkFcfabric + 4 // fcfb_4 + LinkFcfabric5 LinkType = LinkFcfabric + 5 // fcfb_5 + LinkFcfabric6 LinkType = LinkFcfabric + 6 // fcfb_6 + LinkFcfabric7 LinkType = LinkFcfabric + 7 // fcfb_7 + LinkFcfabric8 LinkType = LinkFcfabric + 8 // fcfb_8 + LinkFcfabric9 LinkType = LinkFcfabric + 9 // fcfb_9 + LinkFcfabric10 LinkType = LinkFcfabric + 10 // fcfb_10 + LinkFcfabric11 LinkType = LinkFcfabric + 11 // fcfb_11 + LinkFcfabric12 LinkType = LinkFcfabric + 12 // fcfb_12 + LinkIee802tr LinkType = 800 // tr + LinkIee80211 LinkType = 801 // ieee802.11 + LinkIee80211prism LinkType = 802 // ieee802.11_prism + LinkIee80211Radiotap LinkType = 803 // ieee802.11_radiotap + LinkIee8021154 LinkType = 804 // ieee802.15.4 + LinkIee8021154monitor LinkType = 805 // ieee802.15.4_monitor + LinkPhonet LinkType = 820 // phonet + LinkPhonetpipe LinkType = 821 // phonet_pipe + LinkCaif LinkType = 822 // caif + LinkIP6gre LinkType = 823 // ip6gre + LinkNetlink LinkType = 824 // netlink + Link6Lowpan LinkType = 825 // 6lowpan + LinkVoid LinkType = 65535 // void + LinkNone LinkType = 65534 // nohdr +) diff --git a/pkg/machinery/nethelpers/linktype_linux.go b/pkg/machinery/nethelpers/linktype_linux.go deleted file mode 100644 index cc5ff63f2..000000000 --- a/pkg/machinery/nethelpers/linktype_linux.go +++ /dev/null @@ -1,98 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -package nethelpers - -import "golang.org/x/sys/unix" - -//go:generate stringer -type=LinkType -linecomment -output linktype_string_linux.go - -// LinkType is a link type. -type LinkType uint16 - -// MarshalYAML implements yaml.Marshaler. -func (typ LinkType) MarshalYAML() (interface{}, error) { - return typ.String(), nil -} - -// LinkType constants. -const ( - LinkNetrom LinkType = unix.ARPHRD_NETROM // netrom - LinkEther LinkType = unix.ARPHRD_ETHER // ether - LinkEether LinkType = unix.ARPHRD_EETHER // eether - LinkAx25 LinkType = unix.ARPHRD_AX25 // ax25 - LinkPronet LinkType = unix.ARPHRD_PRONET // pronet - LinkChaos LinkType = unix.ARPHRD_CHAOS // chaos - LinkIee802 LinkType = unix.ARPHRD_IEEE802 // ieee802 - LinkArcnet LinkType = unix.ARPHRD_ARCNET // arcnet - LinkAtalk LinkType = unix.ARPHRD_APPLETLK // atalk - LinkDlci LinkType = unix.ARPHRD_DLCI // dlci - LinkAtm LinkType = unix.ARPHRD_ATM // atm - LinkMetricom LinkType = unix.ARPHRD_METRICOM // metricom - LinkIeee1394 LinkType = unix.ARPHRD_IEEE1394 // ieee1394 - LinkEui64 LinkType = unix.ARPHRD_EUI64 // eui64 - LinkInfiniband LinkType = unix.ARPHRD_INFINIBAND // infiniband - LinkSlip LinkType = unix.ARPHRD_SLIP // slip - LinkCslip LinkType = unix.ARPHRD_CSLIP // cslip - LinkSlip6 LinkType = unix.ARPHRD_SLIP6 // slip6 - LinkCslip6 LinkType = unix.ARPHRD_CSLIP6 // cslip6 - LinkRsrvd LinkType = unix.ARPHRD_RSRVD // rsrvd - LinkAdapt LinkType = unix.ARPHRD_ADAPT // adapt - LinkRose LinkType = unix.ARPHRD_ROSE // rose - LinkX25 LinkType = unix.ARPHRD_X25 // x25 - LinkHwx25 LinkType = unix.ARPHRD_HWX25 // hwx25 - LinkCan LinkType = unix.ARPHRD_CAN // can - LinkPpp LinkType = unix.ARPHRD_PPP // ppp - LinkCisco LinkType = unix.ARPHRD_CISCO // cisco - LinkHdlc LinkType = unix.ARPHRD_HDLC // hdlc - LinkLapb LinkType = unix.ARPHRD_LAPB // lapb - LinkDdcmp LinkType = unix.ARPHRD_DDCMP // ddcmp - LinkRawhdlc LinkType = unix.ARPHRD_RAWHDLC // rawhdlc - LinkTunnel LinkType = unix.ARPHRD_TUNNEL // ipip - LinkTunnel6 LinkType = unix.ARPHRD_TUNNEL6 // tunnel6 - LinkFrad LinkType = unix.ARPHRD_FRAD // frad - LinkSkip LinkType = unix.ARPHRD_SKIP // skip - LinkLoopbck LinkType = unix.ARPHRD_LOOPBACK // loopback - LinkLocaltlk LinkType = unix.ARPHRD_LOCALTLK // localtlk - LinkFddi LinkType = unix.ARPHRD_FDDI // fddi - LinkBif LinkType = unix.ARPHRD_BIF // bif - LinkSit LinkType = unix.ARPHRD_SIT // sit - LinkIpddp LinkType = unix.ARPHRD_IPDDP // ip/ddp - LinkIpgre LinkType = unix.ARPHRD_IPGRE // gre - LinkPimreg LinkType = unix.ARPHRD_PIMREG // pimreg - LinkHippi LinkType = unix.ARPHRD_HIPPI // hippi - LinkAsh LinkType = unix.ARPHRD_ASH // ash - LinkEconet LinkType = unix.ARPHRD_ECONET // econet - LinkIrda LinkType = unix.ARPHRD_IRDA // irda - LinkFcpp LinkType = unix.ARPHRD_FCPP // fcpp - LinkFcal LinkType = unix.ARPHRD_FCAL // fcal - LinkFcpl LinkType = unix.ARPHRD_FCPL // fcpl - LinkFcfabric LinkType = unix.ARPHRD_FCFABRIC // fcfb_0 - LinkFcfabric1 LinkType = unix.ARPHRD_FCFABRIC + 1 // fcfb_1 - LinkFcfabric2 LinkType = unix.ARPHRD_FCFABRIC + 2 // fcfb_2 - LinkFcfabric3 LinkType = unix.ARPHRD_FCFABRIC + 3 // fcfb_3 - LinkFcfabric4 LinkType = unix.ARPHRD_FCFABRIC + 4 // fcfb_4 - LinkFcfabric5 LinkType = unix.ARPHRD_FCFABRIC + 5 // fcfb_5 - LinkFcfabric6 LinkType = unix.ARPHRD_FCFABRIC + 6 // fcfb_6 - LinkFcfabric7 LinkType = unix.ARPHRD_FCFABRIC + 7 // fcfb_7 - LinkFcfabric8 LinkType = unix.ARPHRD_FCFABRIC + 8 // fcfb_8 - LinkFcfabric9 LinkType = unix.ARPHRD_FCFABRIC + 9 // fcfb_9 - LinkFcfabric10 LinkType = unix.ARPHRD_FCFABRIC + 10 // fcfb_10 - LinkFcfabric11 LinkType = unix.ARPHRD_FCFABRIC + 11 // fcfb_11 - LinkFcfabric12 LinkType = unix.ARPHRD_FCFABRIC + 12 // fcfb_12 - LinkIee802tr LinkType = unix.ARPHRD_IEEE802_TR // tr - LinkIee80211 LinkType = unix.ARPHRD_IEEE80211 // ieee802.11 - LinkIee80211prism LinkType = unix.ARPHRD_IEEE80211_PRISM // ieee802.11_prism - LinkIee80211Radiotap LinkType = unix.ARPHRD_IEEE80211_RADIOTAP // ieee802.11_radiotap - LinkIee8021154 LinkType = unix.ARPHRD_IEEE802154 // ieee802.15.4 - LinkIee8021154monitor LinkType = unix.ARPHRD_IEEE802154_MONITOR // ieee802.15.4_monitor - LinkPhonet LinkType = unix.ARPHRD_PHONET // phonet - LinkPhonetpipe LinkType = unix.ARPHRD_PHONET_PIPE // phonet_pipe - LinkCaif LinkType = unix.ARPHRD_CAIF // caif - LinkIP6gre LinkType = unix.ARPHRD_IP6GRE // ip6gre - LinkNetlink LinkType = unix.ARPHRD_NETLINK // netlink - Link6Lowpan LinkType = unix.ARPHRD_6LOWPAN // 6lowpan - LinkVoid LinkType = unix.ARPHRD_VOID // void - LinkNone LinkType = unix.ARPHRD_NONE // nohdr -) diff --git a/pkg/machinery/nethelpers/linktype_string_linux.go b/pkg/machinery/nethelpers/linktype_string.go similarity index 97% rename from pkg/machinery/nethelpers/linktype_string_linux.go rename to pkg/machinery/nethelpers/linktype_string.go index fbae231d4..10de4e7a3 100644 --- a/pkg/machinery/nethelpers/linktype_string_linux.go +++ b/pkg/machinery/nethelpers/linktype_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=LinkType -linecomment -output linktype_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=LinkType -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/routeflag_string_linux.go b/pkg/machinery/nethelpers/routeflag_string.go similarity index 91% rename from pkg/machinery/nethelpers/routeflag_string_linux.go rename to pkg/machinery/nethelpers/routeflag_string.go index 3d4c67938..f5f45b81d 100644 --- a/pkg/machinery/nethelpers/routeflag_string_linux.go +++ b/pkg/machinery/nethelpers/routeflag_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=RouteFlag -linecomment -output routeflag_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=RouteFlag -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/routeflags_linux.go b/pkg/machinery/nethelpers/routeflags.go similarity index 64% rename from pkg/machinery/nethelpers/routeflags_linux.go rename to pkg/machinery/nethelpers/routeflags.go index 93d70304e..c24877344 100644 --- a/pkg/machinery/nethelpers/routeflags_linux.go +++ b/pkg/machinery/nethelpers/routeflags.go @@ -4,12 +4,10 @@ package nethelpers -//go:generate stringer -type=RouteFlag -linecomment -output routeflag_string_linux.go +//go:generate stringer -type=RouteFlag -linecomment import ( "strings" - - "golang.org/x/sys/unix" ) // RouteFlags is a bitmask of RouteFlag. @@ -42,14 +40,14 @@ type RouteFlag uint32 // RouteFlag constants. const ( - RouteNotify RouteFlag = unix.RTM_F_NOTIFY // notify - RouteCloned RouteFlag = unix.RTM_F_CLONED // cloned - RouteEqualize RouteFlag = unix.RTM_F_EQUALIZE // equalize - RoutePrefix RouteFlag = unix.RTM_F_PREFIX // prefix - RouteLookupTable RouteFlag = unix.RTM_F_LOOKUP_TABLE // lookup_table - RouteFIBMatch RouteFlag = unix.RTM_F_FIB_MATCH // fib_match - RouteOffload RouteFlag = unix.RTM_F_OFFLOAD // offload - RouteTrap RouteFlag = unix.RTM_F_TRAP // trap + RouteNotify RouteFlag = 256 << iota // notify + RouteCloned // cloned + RouteEqualize // equalize + RoutePrefix // prefix + RouteLookupTable // lookup_table + RouteFIBMatch // fib_match + RouteOffload // offload + RouteTrap // trap ) // RouteFlagsMask is a supported set of flags to manage. diff --git a/pkg/machinery/nethelpers/routeprotocol_linux.go b/pkg/machinery/nethelpers/routeprotocol.go similarity index 50% rename from pkg/machinery/nethelpers/routeprotocol_linux.go rename to pkg/machinery/nethelpers/routeprotocol.go index b7ccd4124..edd28552d 100644 --- a/pkg/machinery/nethelpers/routeprotocol_linux.go +++ b/pkg/machinery/nethelpers/routeprotocol.go @@ -4,9 +4,7 @@ package nethelpers -import "golang.org/x/sys/unix" - -//go:generate stringer -type=RouteProtocol -linecomment -output routeprotocol_string_linux.go +//go:generate stringer -type=RouteProtocol -linecomment // RouteProtocol is a routing protocol. type RouteProtocol uint8 @@ -18,9 +16,9 @@ func (rp RouteProtocol) MarshalYAML() (interface{}, error) { // RouteType constants. const ( - ProtocolUnspec RouteProtocol = unix.RTPROT_UNSPEC // unspec - ProtocolRedirect RouteProtocol = unix.RTPROT_REDIRECT // redirect - ProtocolKernel RouteProtocol = unix.RTPROT_KERNEL // kernel - ProtocolBoot RouteProtocol = unix.RTPROT_BOOT // boot - ProtocolStatic RouteProtocol = unix.RTPROT_STATIC // static + ProtocolUnspec RouteProtocol = iota // unspec + ProtocolRedirect // redirect + ProtocolKernel // kernel + ProtocolBoot // boot + ProtocolStatic // static ) diff --git a/pkg/machinery/nethelpers/routeprotocol_string_linux.go b/pkg/machinery/nethelpers/routeprotocol_string.go similarity index 85% rename from pkg/machinery/nethelpers/routeprotocol_string_linux.go rename to pkg/machinery/nethelpers/routeprotocol_string.go index a0314a432..6d80b15b4 100644 --- a/pkg/machinery/nethelpers/routeprotocol_string_linux.go +++ b/pkg/machinery/nethelpers/routeprotocol_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=RouteProtocol -linecomment -output routeprotocol_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=RouteProtocol -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/routetype.go b/pkg/machinery/nethelpers/routetype.go new file mode 100644 index 000000000..c7acdc39c --- /dev/null +++ b/pkg/machinery/nethelpers/routetype.go @@ -0,0 +1,31 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package nethelpers + +//go:generate stringer -type=RouteType -linecomment + +// RouteType is a route type. +type RouteType uint8 + +// MarshalYAML implements yaml.Marshaler. +func (rt RouteType) MarshalYAML() (interface{}, error) { + return rt.String(), nil +} + +// RouteType constants. +const ( + TypeUnspec RouteType = iota // unspec + TypeUnicast // unicast + TypeLocal // local + TypeBroadcast // broadcast + TypeAnycast // anycast + TypeMulticast // multicast + TypeBlackhole // blackhole + TypeUnreachable // unreachable + TypeProhibit // prohibit + TypeThrow // throw + TypeNAT // nat + TypeXResolve // xresolve +) diff --git a/pkg/machinery/nethelpers/routetype_linux.go b/pkg/machinery/nethelpers/routetype_linux.go deleted file mode 100644 index f630973b5..000000000 --- a/pkg/machinery/nethelpers/routetype_linux.go +++ /dev/null @@ -1,33 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -package nethelpers - -import "golang.org/x/sys/unix" - -//go:generate stringer -type=RouteType -linecomment -output routetype_string_linux.go - -// RouteType is a route type. -type RouteType uint8 - -// MarshalYAML implements yaml.Marshaler. -func (rt RouteType) MarshalYAML() (interface{}, error) { - return rt.String(), nil -} - -// RouteType constants. -const ( - TypeUnspec RouteType = unix.RTN_UNSPEC // unspec - TypeUnicast RouteType = unix.RTN_UNICAST // unicast - TypeLocal RouteType = unix.RTN_LOCAL // local - TypeBroadcast RouteType = unix.RTN_BROADCAST // broadcast - TypeAnycast RouteType = unix.RTN_ANYCAST // anycast - TypeMulticast RouteType = unix.RTN_MULTICAST // multicast - TypeBlackhole RouteType = unix.RTN_BLACKHOLE // blackhole - TypeUnreachable RouteType = unix.RTN_UNREACHABLE // unreachable - TypeProhibit RouteType = unix.RTN_PROHIBIT // prohibit - TypeThrow RouteType = unix.RTN_THROW // throw - TypeNAT RouteType = unix.RTN_NAT // nat - TypeXResolve RouteType = unix.RTN_XRESOLVE // xresolve -) diff --git a/pkg/machinery/nethelpers/routetype_string_linux.go b/pkg/machinery/nethelpers/routetype_string.go similarity index 89% rename from pkg/machinery/nethelpers/routetype_string_linux.go rename to pkg/machinery/nethelpers/routetype_string.go index 81270da2e..c5e370fdc 100644 --- a/pkg/machinery/nethelpers/routetype_string_linux.go +++ b/pkg/machinery/nethelpers/routetype_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=RouteType -linecomment -output routetype_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=RouteType -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/routingtable_linux.go b/pkg/machinery/nethelpers/routingtable.go similarity index 55% rename from pkg/machinery/nethelpers/routingtable_linux.go rename to pkg/machinery/nethelpers/routingtable.go index 996ab38d6..b586205ee 100644 --- a/pkg/machinery/nethelpers/routingtable_linux.go +++ b/pkg/machinery/nethelpers/routingtable.go @@ -4,9 +4,7 @@ package nethelpers -import "golang.org/x/sys/unix" - -//go:generate stringer -type=RoutingTable -linecomment -output routingtable_string_linux.go +//go:generate stringer -type=RoutingTable -linecomment // RoutingTable is a routing table ID. type RoutingTable uint32 @@ -18,8 +16,8 @@ func (table RoutingTable) MarshalYAML() (interface{}, error) { // RoutingTable constants. const ( - TableUnspec RoutingTable = unix.RT_TABLE_UNSPEC // unspec - TableDefault RoutingTable = unix.RT_TABLE_DEFAULT // default - TableMain RoutingTable = unix.RT_TABLE_MAIN // main - TableLocal RoutingTable = unix.RT_TABLE_LOCAL // local + TableUnspec RoutingTable = 0 // unspec + TableDefault RoutingTable = 253 // default + TableMain RoutingTable = 254 // main + TableLocal RoutingTable = 255 // local ) diff --git a/pkg/machinery/nethelpers/routingtable_string_linux.go b/pkg/machinery/nethelpers/routingtable_string.go similarity index 86% rename from pkg/machinery/nethelpers/routingtable_string_linux.go rename to pkg/machinery/nethelpers/routingtable_string.go index 31f349bdc..811f8160a 100644 --- a/pkg/machinery/nethelpers/routingtable_string_linux.go +++ b/pkg/machinery/nethelpers/routingtable_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=RoutingTable -linecomment -output routingtable_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=RoutingTable -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/scope_linux.go b/pkg/machinery/nethelpers/scope.go similarity index 53% rename from pkg/machinery/nethelpers/scope_linux.go rename to pkg/machinery/nethelpers/scope.go index d49314fb6..21409f9f8 100644 --- a/pkg/machinery/nethelpers/scope_linux.go +++ b/pkg/machinery/nethelpers/scope.go @@ -4,9 +4,7 @@ package nethelpers -import "golang.org/x/sys/unix" - -//go:generate stringer -type=Scope -linecomment -output scope_string_linux.go +//go:generate stringer -type=Scope -linecomment // Scope is an address scope. type Scope uint8 @@ -18,9 +16,9 @@ func (scope Scope) MarshalYAML() (interface{}, error) { // Scope constants. const ( - ScopeGlobal Scope = unix.RT_SCOPE_UNIVERSE // global - ScopeSite Scope = unix.RT_SCOPE_SITE // site - ScopeLink Scope = unix.RT_SCOPE_LINK // link - ScopeHost Scope = unix.RT_SCOPE_HOST // host - ScopeNowhere Scope = unix.RT_SCOPE_NOWHERE // nowhere + ScopeGlobal Scope = 0 // global + ScopeSite Scope = 200 // site + ScopeLink Scope = 253 // link + ScopeHost Scope = 254 // host + ScopeNowhere Scope = 255 // nowhere ) diff --git a/pkg/machinery/nethelpers/scope_string_linux.go b/pkg/machinery/nethelpers/scope_string.go similarity index 88% rename from pkg/machinery/nethelpers/scope_string_linux.go rename to pkg/machinery/nethelpers/scope_string.go index e36324e10..fdd49f682 100644 --- a/pkg/machinery/nethelpers/scope_string_linux.go +++ b/pkg/machinery/nethelpers/scope_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=Scope -linecomment -output scope_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=Scope -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/machinery/nethelpers/vlanprotocol_linux.go b/pkg/machinery/nethelpers/vlanprotocol.go similarity index 64% rename from pkg/machinery/nethelpers/vlanprotocol_linux.go rename to pkg/machinery/nethelpers/vlanprotocol.go index e44f49ac5..aada6ab87 100644 --- a/pkg/machinery/nethelpers/vlanprotocol_linux.go +++ b/pkg/machinery/nethelpers/vlanprotocol.go @@ -4,9 +4,7 @@ package nethelpers -import "golang.org/x/sys/unix" - -//go:generate stringer -type=VLANProtocol -linecomment -output vlanprotocol_string_linux.go +//go:generate stringer -type=VLANProtocol -linecomment // VLANProtocol is a VLAN protocol. type VLANProtocol uint16 @@ -18,6 +16,6 @@ func (proto VLANProtocol) MarshalYAML() (interface{}, error) { // VLANProtocol constants. const ( - VLANProtocol8021Q VLANProtocol = unix.ETH_P_8021Q // 802.1q - VLANProtocol8021AD VLANProtocol = unix.ETH_P_8021AD // 802.1ad + VLANProtocol8021Q VLANProtocol = 33024 // 802.1q + VLANProtocol8021AD VLANProtocol = 34984 // 802.1ad ) diff --git a/pkg/machinery/nethelpers/vlanprotocol_string_linux.go b/pkg/machinery/nethelpers/vlanprotocol_string.go similarity index 83% rename from pkg/machinery/nethelpers/vlanprotocol_string_linux.go rename to pkg/machinery/nethelpers/vlanprotocol_string.go index f5090edc9..4ba4138cf 100644 --- a/pkg/machinery/nethelpers/vlanprotocol_string_linux.go +++ b/pkg/machinery/nethelpers/vlanprotocol_string.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type=VLANProtocol -linecomment -output vlanprotocol_string_linux.go"; DO NOT EDIT. +// Code generated by "stringer -type=VLANProtocol -linecomment"; DO NOT EDIT. package nethelpers diff --git a/pkg/resources/k8s/condition.go b/pkg/resources/k8s/condition.go index 01103cdb9..940f3c7a4 100644 --- a/pkg/resources/k8s/condition.go +++ b/pkg/resources/k8s/condition.go @@ -2,9 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux -// +build linux - package k8s import ( diff --git a/pkg/resources/network/address_spec.go b/pkg/resources/network/address_spec.go index b24892974..40ce7a226 100644 --- a/pkg/resources/network/address_spec.go +++ b/pkg/resources/network/address_spec.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( diff --git a/pkg/resources/network/address_status.go b/pkg/resources/network/address_status.go index 94ceb75b4..35e88f872 100644 --- a/pkg/resources/network/address_status.go +++ b/pkg/resources/network/address_status.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( diff --git a/pkg/resources/network/consts.go b/pkg/resources/network/consts.go deleted file mode 100644 index 12cd3aebe..000000000 --- a/pkg/resources/network/consts.go +++ /dev/null @@ -1,20 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -package network - -import ( - "github.com/cosi-project/runtime/pkg/resource" -) - -// NamespaceName contains resources related to networking. -const NamespaceName resource.Namespace = "network" - -// ConfigNamespaceName contains umerged resources related to networking generate from the configuration. -// -// Resources in the ConfigNamespaceName namespace are merged to produce final versions in the NamespaceName namespace. -const ConfigNamespaceName resource.Namespace = "network-config" - -// LinkStatusType is type of LinkStatus resource. -const LinkStatusType = resource.Type("LinkStatuses.net.talos.dev") diff --git a/pkg/resources/network/link.go b/pkg/resources/network/link.go index c6a0eb8e5..f89ba72b2 100644 --- a/pkg/resources/network/link.go +++ b/pkg/resources/network/link.go @@ -2,18 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( - "encoding/binary" "net" "sort" "time" - "github.com/mdlayher/netlink" - "golang.org/x/sys/unix" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "inet.af/netaddr" @@ -29,38 +24,6 @@ type VLANSpec struct { Protocol nethelpers.VLANProtocol `yaml:"vlanProtocol"` } -// Encode the VLANSpec into netlink attributes. -func (vlan *VLANSpec) Encode() ([]byte, error) { - encoder := netlink.NewAttributeEncoder() - - encoder.Uint16(unix.IFLA_VLAN_ID, vlan.VID) - - buf := make([]byte, 2) - binary.BigEndian.PutUint16(buf, uint16(vlan.Protocol)) - encoder.Bytes(unix.IFLA_VLAN_PROTOCOL, buf) - - return encoder.Encode() -} - -// Decode the VLANSpec from netlink attributes. -func (vlan *VLANSpec) Decode(data []byte) error { - decoder, err := netlink.NewAttributeDecoder(data) - if err != nil { - return err - } - - for decoder.Next() { - switch decoder.Type() { - case unix.IFLA_VLAN_ID: - vlan.VID = decoder.Uint16() - case unix.IFLA_VLAN_PROTOCOL: - vlan.Protocol = nethelpers.VLANProtocol(binary.BigEndian.Uint16(decoder.Bytes())) - } - } - - return decoder.Err() -} - // BondMasterSpec describes bond settings if Kind == "bond". type BondMasterSpec struct { Mode nethelpers.BondMode `yaml:"mode"` @@ -116,144 +79,6 @@ func (bond *BondMasterSpec) FillDefaults() { } } -// Encode the BondMasterSpec into netlink attributes. -// -//nolint:gocyclo -func (bond *BondMasterSpec) Encode() ([]byte, error) { - encoder := netlink.NewAttributeEncoder() - - encoder.Uint8(unix.IFLA_BOND_MODE, uint8(bond.Mode)) - encoder.Uint8(unix.IFLA_BOND_XMIT_HASH_POLICY, uint8(bond.HashPolicy)) - - if bond.Mode == nethelpers.BondMode8023AD { - encoder.Uint8(unix.IFLA_BOND_AD_LACP_RATE, uint8(bond.LACPRate)) - } - - if bond.Mode != nethelpers.BondMode8023AD && bond.Mode != nethelpers.BondModeALB && bond.Mode != nethelpers.BondModeTLB { - encoder.Uint32(unix.IFLA_BOND_ARP_VALIDATE, uint32(bond.ARPValidate)) - } - - encoder.Uint32(unix.IFLA_BOND_ARP_ALL_TARGETS, uint32(bond.ARPAllTargets)) - - if bond.Mode == nethelpers.BondModeActiveBackup || bond.Mode == nethelpers.BondModeALB || bond.Mode == nethelpers.BondModeTLB { - encoder.Uint32(unix.IFLA_BOND_PRIMARY, bond.PrimaryIndex) - } - - encoder.Uint8(unix.IFLA_BOND_PRIMARY_RESELECT, uint8(bond.PrimaryReselect)) - encoder.Uint8(unix.IFLA_BOND_FAIL_OVER_MAC, uint8(bond.FailOverMac)) - encoder.Uint8(unix.IFLA_BOND_AD_SELECT, uint8(bond.ADSelect)) - encoder.Uint32(unix.IFLA_BOND_MIIMON, bond.MIIMon) - - if bond.MIIMon != 0 { - encoder.Uint32(unix.IFLA_BOND_UPDELAY, bond.UpDelay) - encoder.Uint32(unix.IFLA_BOND_DOWNDELAY, bond.DownDelay) - } - - if bond.Mode != nethelpers.BondMode8023AD && bond.Mode != nethelpers.BondModeALB && bond.Mode != nethelpers.BondModeTLB { - encoder.Uint32(unix.IFLA_BOND_ARP_INTERVAL, bond.ARPInterval) - } - - encoder.Uint32(unix.IFLA_BOND_RESEND_IGMP, bond.ResendIGMP) - encoder.Uint32(unix.IFLA_BOND_MIN_LINKS, bond.MinLinks) - encoder.Uint32(unix.IFLA_BOND_LP_INTERVAL, bond.LPInterval) - - if bond.Mode == nethelpers.BondModeRoundrobin { - encoder.Uint32(unix.IFLA_BOND_PACKETS_PER_SLAVE, bond.PacketsPerSlave) - } - - encoder.Uint8(unix.IFLA_BOND_NUM_PEER_NOTIF, bond.NumPeerNotif) - - if bond.Mode == nethelpers.BondModeALB || bond.Mode == nethelpers.BondModeTLB { - encoder.Uint8(unix.IFLA_BOND_TLB_DYNAMIC_LB, bond.TLBDynamicLB) - } - - encoder.Uint8(unix.IFLA_BOND_ALL_SLAVES_ACTIVE, bond.AllSlavesActive) - - var useCarrier uint8 - - if bond.UseCarrier { - useCarrier = 1 - } - - encoder.Uint8(unix.IFLA_BOND_USE_CARRIER, useCarrier) - - if bond.Mode == nethelpers.BondMode8023AD { - encoder.Uint16(unix.IFLA_BOND_AD_ACTOR_SYS_PRIO, bond.ADActorSysPrio) - encoder.Uint16(unix.IFLA_BOND_AD_USER_PORT_KEY, bond.ADUserPortKey) - } - - if bond.MIIMon != 0 { - encoder.Uint32(unix.IFLA_BOND_PEER_NOTIF_DELAY, bond.PeerNotifyDelay) - } - - return encoder.Encode() -} - -// Decode the BondMasterSpec from netlink attributes. -// -//nolint:gocyclo,cyclop -func (bond *BondMasterSpec) Decode(data []byte) error { - decoder, err := netlink.NewAttributeDecoder(data) - if err != nil { - return err - } - - for decoder.Next() { - switch decoder.Type() { - case unix.IFLA_BOND_MODE: - bond.Mode = nethelpers.BondMode(decoder.Uint8()) - case unix.IFLA_BOND_XMIT_HASH_POLICY: - bond.HashPolicy = nethelpers.BondXmitHashPolicy(decoder.Uint8()) - case unix.IFLA_BOND_AD_LACP_RATE: - bond.LACPRate = nethelpers.LACPRate(decoder.Uint8()) - case unix.IFLA_BOND_ARP_VALIDATE: - bond.ARPValidate = nethelpers.ARPValidate(decoder.Uint32()) - case unix.IFLA_BOND_ARP_ALL_TARGETS: - bond.ARPAllTargets = nethelpers.ARPAllTargets(decoder.Uint32()) - case unix.IFLA_BOND_PRIMARY: - bond.PrimaryIndex = decoder.Uint32() - case unix.IFLA_BOND_PRIMARY_RESELECT: - bond.PrimaryReselect = nethelpers.PrimaryReselect(decoder.Uint8()) - case unix.IFLA_BOND_FAIL_OVER_MAC: - bond.FailOverMac = nethelpers.FailOverMAC(decoder.Uint8()) - case unix.IFLA_BOND_AD_SELECT: - bond.ADSelect = nethelpers.ADSelect(decoder.Uint8()) - case unix.IFLA_BOND_MIIMON: - bond.MIIMon = decoder.Uint32() - case unix.IFLA_BOND_UPDELAY: - bond.UpDelay = decoder.Uint32() - case unix.IFLA_BOND_DOWNDELAY: - bond.DownDelay = decoder.Uint32() - case unix.IFLA_BOND_ARP_INTERVAL: - bond.ARPInterval = decoder.Uint32() - case unix.IFLA_BOND_RESEND_IGMP: - bond.ResendIGMP = decoder.Uint32() - case unix.IFLA_BOND_MIN_LINKS: - bond.MinLinks = decoder.Uint32() - case unix.IFLA_BOND_LP_INTERVAL: - bond.LPInterval = decoder.Uint32() - case unix.IFLA_BOND_PACKETS_PER_SLAVE: - bond.PacketsPerSlave = decoder.Uint32() - case unix.IFLA_BOND_NUM_PEER_NOTIF: - bond.NumPeerNotif = decoder.Uint8() - case unix.IFLA_BOND_TLB_DYNAMIC_LB: - bond.TLBDynamicLB = decoder.Uint8() - case unix.IFLA_BOND_ALL_SLAVES_ACTIVE: - bond.AllSlavesActive = decoder.Uint8() - case unix.IFLA_BOND_USE_CARRIER: - bond.UseCarrier = decoder.Uint8() == 1 - case unix.IFLA_BOND_AD_ACTOR_SYS_PRIO: - bond.ADActorSysPrio = decoder.Uint16() - case unix.IFLA_BOND_AD_USER_PORT_KEY: - bond.ADUserPortKey = decoder.Uint16() - case unix.IFLA_BOND_PEER_NOTIF_DELAY: - bond.PeerNotifyDelay = decoder.Uint32() - } - } - - return decoder.Err() -} - // WireguardSpec describes Wireguard settings if Kind == "wireguard". type WireguardSpec struct { // PrivateKey is used to configure the link, present only in the LinkSpec. diff --git a/pkg/resources/network/link_linux.go b/pkg/resources/network/link_linux.go new file mode 100644 index 000000000..8eae8077a --- /dev/null +++ b/pkg/resources/network/link_linux.go @@ -0,0 +1,184 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package network + +import ( + "encoding/binary" + + "github.com/mdlayher/netlink" + "golang.org/x/sys/unix" + + "github.com/talos-systems/talos/pkg/machinery/nethelpers" +) + +// Encode the VLANSpec into netlink attributes. +func (vlan *VLANSpec) Encode() ([]byte, error) { + encoder := netlink.NewAttributeEncoder() + + encoder.Uint16(unix.IFLA_VLAN_ID, vlan.VID) + + buf := make([]byte, 2) + binary.BigEndian.PutUint16(buf, uint16(vlan.Protocol)) + encoder.Bytes(unix.IFLA_VLAN_PROTOCOL, buf) + + return encoder.Encode() +} + +// Decode the VLANSpec from netlink attributes. +func (vlan *VLANSpec) Decode(data []byte) error { + decoder, err := netlink.NewAttributeDecoder(data) + if err != nil { + return err + } + + for decoder.Next() { + switch decoder.Type() { + case unix.IFLA_VLAN_ID: + vlan.VID = decoder.Uint16() + case unix.IFLA_VLAN_PROTOCOL: + vlan.Protocol = nethelpers.VLANProtocol(binary.BigEndian.Uint16(decoder.Bytes())) + } + } + + return decoder.Err() +} + +// Encode the BondMasterSpec into netlink attributes. +// +//nolint:gocyclo +func (bond *BondMasterSpec) Encode() ([]byte, error) { + encoder := netlink.NewAttributeEncoder() + + encoder.Uint8(unix.IFLA_BOND_MODE, uint8(bond.Mode)) + encoder.Uint8(unix.IFLA_BOND_XMIT_HASH_POLICY, uint8(bond.HashPolicy)) + + if bond.Mode == nethelpers.BondMode8023AD { + encoder.Uint8(unix.IFLA_BOND_AD_LACP_RATE, uint8(bond.LACPRate)) + } + + if bond.Mode != nethelpers.BondMode8023AD && bond.Mode != nethelpers.BondModeALB && bond.Mode != nethelpers.BondModeTLB { + encoder.Uint32(unix.IFLA_BOND_ARP_VALIDATE, uint32(bond.ARPValidate)) + } + + encoder.Uint32(unix.IFLA_BOND_ARP_ALL_TARGETS, uint32(bond.ARPAllTargets)) + + if bond.Mode == nethelpers.BondModeActiveBackup || bond.Mode == nethelpers.BondModeALB || bond.Mode == nethelpers.BondModeTLB { + encoder.Uint32(unix.IFLA_BOND_PRIMARY, bond.PrimaryIndex) + } + + encoder.Uint8(unix.IFLA_BOND_PRIMARY_RESELECT, uint8(bond.PrimaryReselect)) + encoder.Uint8(unix.IFLA_BOND_FAIL_OVER_MAC, uint8(bond.FailOverMac)) + encoder.Uint8(unix.IFLA_BOND_AD_SELECT, uint8(bond.ADSelect)) + encoder.Uint32(unix.IFLA_BOND_MIIMON, bond.MIIMon) + + if bond.MIIMon != 0 { + encoder.Uint32(unix.IFLA_BOND_UPDELAY, bond.UpDelay) + encoder.Uint32(unix.IFLA_BOND_DOWNDELAY, bond.DownDelay) + } + + if bond.Mode != nethelpers.BondMode8023AD && bond.Mode != nethelpers.BondModeALB && bond.Mode != nethelpers.BondModeTLB { + encoder.Uint32(unix.IFLA_BOND_ARP_INTERVAL, bond.ARPInterval) + } + + encoder.Uint32(unix.IFLA_BOND_RESEND_IGMP, bond.ResendIGMP) + encoder.Uint32(unix.IFLA_BOND_MIN_LINKS, bond.MinLinks) + encoder.Uint32(unix.IFLA_BOND_LP_INTERVAL, bond.LPInterval) + + if bond.Mode == nethelpers.BondModeRoundrobin { + encoder.Uint32(unix.IFLA_BOND_PACKETS_PER_SLAVE, bond.PacketsPerSlave) + } + + encoder.Uint8(unix.IFLA_BOND_NUM_PEER_NOTIF, bond.NumPeerNotif) + + if bond.Mode == nethelpers.BondModeALB || bond.Mode == nethelpers.BondModeTLB { + encoder.Uint8(unix.IFLA_BOND_TLB_DYNAMIC_LB, bond.TLBDynamicLB) + } + + encoder.Uint8(unix.IFLA_BOND_ALL_SLAVES_ACTIVE, bond.AllSlavesActive) + + var useCarrier uint8 + + if bond.UseCarrier { + useCarrier = 1 + } + + encoder.Uint8(unix.IFLA_BOND_USE_CARRIER, useCarrier) + + if bond.Mode == nethelpers.BondMode8023AD { + encoder.Uint16(unix.IFLA_BOND_AD_ACTOR_SYS_PRIO, bond.ADActorSysPrio) + encoder.Uint16(unix.IFLA_BOND_AD_USER_PORT_KEY, bond.ADUserPortKey) + } + + if bond.MIIMon != 0 { + encoder.Uint32(unix.IFLA_BOND_PEER_NOTIF_DELAY, bond.PeerNotifyDelay) + } + + return encoder.Encode() +} + +// Decode the BondMasterSpec from netlink attributes. +// +//nolint:gocyclo,cyclop +func (bond *BondMasterSpec) Decode(data []byte) error { + decoder, err := netlink.NewAttributeDecoder(data) + if err != nil { + return err + } + + for decoder.Next() { + switch decoder.Type() { + case unix.IFLA_BOND_MODE: + bond.Mode = nethelpers.BondMode(decoder.Uint8()) + case unix.IFLA_BOND_XMIT_HASH_POLICY: + bond.HashPolicy = nethelpers.BondXmitHashPolicy(decoder.Uint8()) + case unix.IFLA_BOND_AD_LACP_RATE: + bond.LACPRate = nethelpers.LACPRate(decoder.Uint8()) + case unix.IFLA_BOND_ARP_VALIDATE: + bond.ARPValidate = nethelpers.ARPValidate(decoder.Uint32()) + case unix.IFLA_BOND_ARP_ALL_TARGETS: + bond.ARPAllTargets = nethelpers.ARPAllTargets(decoder.Uint32()) + case unix.IFLA_BOND_PRIMARY: + bond.PrimaryIndex = decoder.Uint32() + case unix.IFLA_BOND_PRIMARY_RESELECT: + bond.PrimaryReselect = nethelpers.PrimaryReselect(decoder.Uint8()) + case unix.IFLA_BOND_FAIL_OVER_MAC: + bond.FailOverMac = nethelpers.FailOverMAC(decoder.Uint8()) + case unix.IFLA_BOND_AD_SELECT: + bond.ADSelect = nethelpers.ADSelect(decoder.Uint8()) + case unix.IFLA_BOND_MIIMON: + bond.MIIMon = decoder.Uint32() + case unix.IFLA_BOND_UPDELAY: + bond.UpDelay = decoder.Uint32() + case unix.IFLA_BOND_DOWNDELAY: + bond.DownDelay = decoder.Uint32() + case unix.IFLA_BOND_ARP_INTERVAL: + bond.ARPInterval = decoder.Uint32() + case unix.IFLA_BOND_RESEND_IGMP: + bond.ResendIGMP = decoder.Uint32() + case unix.IFLA_BOND_MIN_LINKS: + bond.MinLinks = decoder.Uint32() + case unix.IFLA_BOND_LP_INTERVAL: + bond.LPInterval = decoder.Uint32() + case unix.IFLA_BOND_PACKETS_PER_SLAVE: + bond.PacketsPerSlave = decoder.Uint32() + case unix.IFLA_BOND_NUM_PEER_NOTIF: + bond.NumPeerNotif = decoder.Uint8() + case unix.IFLA_BOND_TLB_DYNAMIC_LB: + bond.TLBDynamicLB = decoder.Uint8() + case unix.IFLA_BOND_ALL_SLAVES_ACTIVE: + bond.AllSlavesActive = decoder.Uint8() + case unix.IFLA_BOND_USE_CARRIER: + bond.UseCarrier = decoder.Uint8() == 1 + case unix.IFLA_BOND_AD_ACTOR_SYS_PRIO: + bond.ADActorSysPrio = decoder.Uint16() + case unix.IFLA_BOND_AD_USER_PORT_KEY: + bond.ADUserPortKey = decoder.Uint16() + case unix.IFLA_BOND_PEER_NOTIF_DELAY: + bond.PeerNotifyDelay = decoder.Uint32() + } + } + + return decoder.Err() +} diff --git a/pkg/resources/network/link_spec.go b/pkg/resources/network/link_spec.go index 4464dd6f2..8998af6e3 100644 --- a/pkg/resources/network/link_spec.go +++ b/pkg/resources/network/link_spec.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( diff --git a/pkg/resources/network/link_status.go b/pkg/resources/network/link_status.go index 8f130c782..69a3c5c6e 100644 --- a/pkg/resources/network/link_status.go +++ b/pkg/resources/network/link_status.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( @@ -15,6 +13,9 @@ import ( "github.com/talos-systems/talos/pkg/machinery/nethelpers" ) +// LinkStatusType is type of LinkStatus resource. +const LinkStatusType = resource.Type("LinkStatuses.net.talos.dev") + // LinkStatus resource holds physical network link status. type LinkStatus struct { md resource.Metadata diff --git a/pkg/resources/network/network.go b/pkg/resources/network/network.go index e20f01ffc..a82855f6b 100644 --- a/pkg/resources/network/network.go +++ b/pkg/resources/network/network.go @@ -2,19 +2,26 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - // Package network provides resources which describe networking subsystem state. package network import ( "fmt" + "github.com/cosi-project/runtime/pkg/resource" "inet.af/netaddr" "github.com/talos-systems/talos/pkg/machinery/nethelpers" ) +// NamespaceName contains resources related to networking. +const NamespaceName resource.Namespace = "network" + +// ConfigNamespaceName contains umerged resources related to networking generate from the configuration. +// +// Resources in the ConfigNamespaceName namespace are merged to produce final versions in the NamespaceName namespace. +const ConfigNamespaceName resource.Namespace = "network-config" + // AddressID builds ID (primary key) for the address. func AddressID(linkName string, addr netaddr.IPPrefix) string { return fmt.Sprintf("%s/%s", linkName, addr) diff --git a/pkg/resources/network/route_spec.go b/pkg/resources/network/route_spec.go index 49b0ce47d..10560f61c 100644 --- a/pkg/resources/network/route_spec.go +++ b/pkg/resources/network/route_spec.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import ( diff --git a/pkg/resources/network/route_status.go b/pkg/resources/network/route_status.go index 1fcd81d95..fb9f88dd4 100644 --- a/pkg/resources/network/route_status.go +++ b/pkg/resources/network/route_status.go @@ -2,8 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build linux - package network import (