| 1508 | } |
| 1509 | |
| 1510 | static int |
| 1511 | vxlan_setup_socket(struct vxlan_softc *sc) |
| 1512 | { |
| 1513 | struct vxlan_socket *vso; |
| 1514 | struct ifnet *ifp; |
| 1515 | union vxlan_sockaddr *saddr, *daddr; |
| 1516 | int multicast, error; |
| 1517 | |
| 1518 | vso = NULL; |
| 1519 | ifp = sc->vxl_ifp; |
| 1520 | saddr = &sc->vxl_src_addr; |
| 1521 | daddr = &sc->vxl_dst_addr; |
| 1522 | |
| 1523 | multicast = vxlan_sockaddr_in_multicast(daddr); |
| 1524 | MPASS(multicast != -1); |
| 1525 | sc->vxl_vso_mc_index = -1; |
| 1526 | |
| 1527 | /* |
| 1528 | * Try to create the socket. If that fails, attempt to use an |
| 1529 | * existing socket. |
| 1530 | */ |
| 1531 | error = vxlan_socket_create(ifp, multicast, saddr, &vso); |
| 1532 | if (error) { |
| 1533 | if (multicast != 0) |
| 1534 | vso = vxlan_socket_mc_lookup(saddr); |
| 1535 | else |
| 1536 | vso = vxlan_socket_lookup(saddr); |
| 1537 | |
| 1538 | if (vso == NULL) { |
| 1539 | if_printf(ifp, "cannot create socket (error: %d), " |
| 1540 | "and no existing socket found\n", error); |
| 1541 | goto out; |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | if (multicast != 0) { |
| 1546 | error = vxlan_setup_multicast(sc); |
| 1547 | if (error) |
| 1548 | goto out; |
| 1549 | |
| 1550 | error = vxlan_socket_mc_add_group(vso, daddr, saddr, |
| 1551 | sc->vxl_mc_ifindex, &sc->vxl_vso_mc_index); |
| 1552 | if (error) |
| 1553 | goto out; |
| 1554 | } |
| 1555 | |
| 1556 | sc->vxl_sock = vso; |
| 1557 | error = vxlan_socket_insert_softc(vso, sc); |
| 1558 | if (error) { |
| 1559 | sc->vxl_sock = NULL; |
| 1560 | if_printf(ifp, "network identifier %d already exists in " |
| 1561 | "this socket\n", sc->vxl_vni); |
| 1562 | goto out; |
| 1563 | } |
| 1564 | |
| 1565 | return (0); |
| 1566 | |
| 1567 | out: |
no test coverage detected