NewRoute implements inet.Stack.NewRoute.
(ctx context.Context, msg *nlmsg.Message)
| 1073 | |
| 1074 | // NewRoute implements inet.Stack.NewRoute. |
| 1075 | func (s *Stack) NewRoute(ctx context.Context, msg *nlmsg.Message) *syserr.Error { |
| 1076 | localRoute, err := s.localRoute(msg) |
| 1077 | if err != nil { |
| 1078 | return err |
| 1079 | } |
| 1080 | found := false |
| 1081 | for _, rt := range s.Stack.GetRouteTable() { |
| 1082 | if localRoute.Equal(rt) { |
| 1083 | found = true |
| 1084 | break |
| 1085 | } |
| 1086 | } |
| 1087 | flags := msg.Header().Flags |
| 1088 | switch { |
| 1089 | case !found && flags&linux.NLM_F_CREATE == linux.NLM_F_CREATE: |
| 1090 | s.Stack.AddRoute(localRoute) |
| 1091 | case found && flags&linux.NLM_F_REPLACE != linux.NLM_F_REPLACE: |
| 1092 | return syserr.ErrExists |
| 1093 | } |
| 1094 | if flags&linux.NLM_F_REPLACE == linux.NLM_F_REPLACE { |
| 1095 | s.Stack.ReplaceRoute(localRoute) |
| 1096 | } |
| 1097 | return nil |
| 1098 | } |
| 1099 | |
| 1100 | // IPTables returns the stack's iptables. |
| 1101 | func (s *Stack) IPTables() (*stack.IPTables, error) { |
nothing calls this directly
no test coverage detected