MCPcopy
hub / github.com/rook/rook / ipAddrOutput

Function ipAddrOutput

pkg/operator/ceph/controller/network_test.go:838–897  ·  view source on GitHub ↗

generate 'ip --json address show dev ' output with some number of / -es also contains extra IPv6 SLAAC addrs that are often present in containers

(iface string, ipsWithPrefixLens ...string)

Source from the content-addressed store, hash-verified

836// generate 'ip --json address show dev <iface>' output with some number of <ip>/<prefix>-es
837// also contains extra IPv6 SLAAC addrs that are often present in containers
838func ipAddrOutput(iface string, ipsWithPrefixLens ...string) string {
839 ipsInJson := ""
840 for _, ipWithPrefix := range ipsWithPrefixLens {
841 s := strings.Split(ipWithPrefix, "/")
842 ip := s[0]
843 prefix := s[1]
844 // specifically omit "family": "inet" from the output so it's certain that field isn't used
845 // when parsing IPv4 vs IPv6 addrs
846 ipsInJson = ipsInJson + `
847 {
848 "local": "` + ip + `",
849 "prefixlen": ` + prefix + `,
850 "scope": "global",
851 "valid_life_time": 4294967295,
852 "preferred_life_time": 4294967295
853 },`
854 }
855 out := `[
856 {
857 "ifindex": 3,
858 "link_index": 2,
859 "ifname": "` + iface + `",
860 "flags": [
861 "BROADCAST",
862 "MULTICAST",
863 "UP",
864 "LOWER_UP"
865 ],
866 "mtu": 1500,
867 "qdisc": "noqueue",
868 "operstate": "UP",
869 "group": "default",
870 "link_type": "ether",
871 "address": "8e:ec:4a:e3:1b:96",
872 "broadcast": "ff:ff:ff:ff:ff:ff",
873 "link_netnsid": 0,
874 "addr_info": [
875 {
876 "family": "inet6",
877 "local": "fd4e:7658:764f:15c4:8cec:4aff:fee3:1b96",
878 "prefixlen": 64,
879 "scope": "global",
880 "dynamic": true,
881 "mngtmpaddr": true,
882 "valid_life_time": 2591998,
883 "preferred_life_time": 604798
884 },` + ipsInJson + `
885 {
886 "family": "inet6",
887 "local": "fe80::8cec:4aff:fee3:1b96",
888 "prefixlen": 64,
889 "scope": "link",
890 "valid_life_time": 4294967295,
891 "preferred_life_time": 4294967295
892 }
893 ]
894 }
895]`

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected