| 1028 | } |
| 1029 | |
| 1030 | static int |
| 1031 | vxlan_socket_create(struct ifnet *ifp, int multicast, |
| 1032 | const union vxlan_sockaddr *saddr, struct vxlan_socket **vsop) |
| 1033 | { |
| 1034 | union vxlan_sockaddr laddr; |
| 1035 | struct vxlan_socket *vso; |
| 1036 | int error; |
| 1037 | |
| 1038 | laddr = *saddr; |
| 1039 | |
| 1040 | /* |
| 1041 | * If this socket will be multicast, then only the local port |
| 1042 | * must be specified when binding. |
| 1043 | */ |
| 1044 | if (multicast != 0) { |
| 1045 | if (VXLAN_SOCKADDR_IS_IPV4(&laddr)) |
| 1046 | laddr.in4.sin_addr.s_addr = INADDR_ANY; |
| 1047 | #ifdef INET6 |
| 1048 | else |
| 1049 | laddr.in6.sin6_addr = in6addr_any; |
| 1050 | #endif |
| 1051 | } |
| 1052 | |
| 1053 | vso = vxlan_socket_alloc(&laddr); |
| 1054 | if (vso == NULL) |
| 1055 | return (ENOMEM); |
| 1056 | |
| 1057 | error = vxlan_socket_init(vso, ifp); |
| 1058 | if (error) |
| 1059 | goto fail; |
| 1060 | |
| 1061 | error = vxlan_socket_bind(vso, ifp); |
| 1062 | if (error) |
| 1063 | goto fail; |
| 1064 | |
| 1065 | /* |
| 1066 | * There is a small window between the bind completing and |
| 1067 | * inserting the socket, so that a concurrent create may fail. |
| 1068 | * Let's not worry about that for now. |
| 1069 | */ |
| 1070 | vxlan_socket_insert(vso); |
| 1071 | *vsop = vso; |
| 1072 | |
| 1073 | return (0); |
| 1074 | |
| 1075 | fail: |
| 1076 | vxlan_socket_destroy(vso); |
| 1077 | |
| 1078 | return (error); |
| 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | vxlan_socket_ifdetach(struct vxlan_socket *vso, struct ifnet *ifp, |
no test coverage detected