RouteTable implements inet.Stack.RouteTable.
()
| 912 | |
| 913 | // RouteTable implements inet.Stack.RouteTable. |
| 914 | func (s *Stack) RouteTable() []inet.Route { |
| 915 | var routeTable []inet.Route |
| 916 | |
| 917 | for _, rt := range s.Stack.GetRouteTable() { |
| 918 | var family uint8 |
| 919 | switch rt.Destination.ID().BitLen() { |
| 920 | case header.IPv4AddressSizeBits: |
| 921 | family = linux.AF_INET |
| 922 | case header.IPv6AddressSizeBits: |
| 923 | family = linux.AF_INET6 |
| 924 | default: |
| 925 | log.Warningf("Unknown network protocol in route %+v", rt) |
| 926 | continue |
| 927 | } |
| 928 | |
| 929 | dstAddr := rt.Destination.ID() |
| 930 | routeTable = append(routeTable, inet.Route{ |
| 931 | Family: family, |
| 932 | DstLen: uint8(rt.Destination.Prefix()), // The CIDR prefix for the destination. |
| 933 | |
| 934 | // Always return unspecified protocol since we have no notion of |
| 935 | // protocol for routes. |
| 936 | Protocol: linux.RTPROT_UNSPEC, |
| 937 | // Set statically to LINK scope for now. |
| 938 | // |
| 939 | // TODO(gvisor.dev/issue/595): Set scope for routes. |
| 940 | Scope: linux.RT_SCOPE_LINK, |
| 941 | Type: linux.RTN_UNICAST, |
| 942 | |
| 943 | DstAddr: dstAddr.AsSlice(), |
| 944 | OutputInterface: int32(rt.NIC), |
| 945 | GatewayAddr: rt.Gateway.AsSlice(), |
| 946 | }) |
| 947 | } |
| 948 | |
| 949 | return routeTable |
| 950 | } |
| 951 | |
| 952 | // localRoute constructs a local route from the netlink message. |
| 953 | func (s *Stack) localRoute(msg *nlmsg.Message) (tcpip.Route, *syserr.Error) { |