summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2023-07-11 10:23:37 -0400
committerGitHub <noreply@github.com>2023-07-11 10:23:37 -0400
commitf46dc78367ec9554696dd8ef0e5e57c6ff94cf81 (patch)
tree935ef41898e2346dc571c4cdef44c64ac568c36f
parentd602e0174512c77bc7c5884324a044e0faf878d4 (diff)
parent60b77869e554b6d2b38ea507031926f4effe390a (diff)
Merge pull request #13880 from mjstapp/fix_ospf_intf_socket
ospfd: fix per-interface sockets
-rw-r--r--ospfd/ospf_interface.c13
-rw-r--r--ospfd/ospf_network.c38
2 files changed, 36 insertions, 15 deletions
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 9e6acdbf0d..840756c05c 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -271,6 +271,10 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
QOBJ_REG(oi, ospf_interface);
+ /* If first oi, check per-intf write socket */
+ if (ospf->oi_running && ospf->intf_socket_enabled)
+ ospf_ifp_sock_init(ifp);
+
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: ospf interface %s vrf %s id %u created",
__func__, ifp->name, ospf_get_name(ospf),
@@ -327,6 +331,8 @@ void ospf_if_cleanup(struct ospf_interface *oi)
void ospf_if_free(struct ospf_interface *oi)
{
+ struct interface *ifp = oi->ifp;
+
ospf_if_down(oi);
ospf_fifo_free(oi->obuf);
@@ -361,6 +367,10 @@ void ospf_if_free(struct ospf_interface *oi)
event_cancel_event(master, oi);
+ /* If last oi, close per-interface socket */
+ if (ospf_oi_count(ifp) == 0)
+ ospf_ifp_sock_close(ifp);
+
memset(oi, 0, sizeof(*oi));
XFREE(MTYPE_OSPF_IF, oi);
}
@@ -1404,7 +1414,8 @@ static int ospf_ifp_up(struct interface *ifp)
/* Open per-intf write socket if configured */
ospf = ifp->vrf->info;
- if (ospf && ospf->intf_socket_enabled)
+
+ if (ospf && ospf->oi_running && ospf->intf_socket_enabled)
ospf_ifp_sock_init(ifp);
ospf_if_recalculate_output_cost(ifp);
diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c
index aff8ed05c7..801f75ad18 100644
--- a/ospfd/ospf_network.c
+++ b/ospfd/ospf_network.c
@@ -159,7 +159,8 @@ int ospf_if_ipmulticast(int fd, struct prefix *p, ifindex_t ifindex)
* Helper to open and set up a socket; returns the new fd on success,
* -1 on error.
*/
-static int sock_init_common(vrf_id_t vrf_id, const char *name, int *pfd)
+static int sock_init_common(vrf_id_t vrf_id, const char *name, int proto,
+ int *pfd)
{
int ospf_sock;
int ret, hincl = 1;
@@ -170,8 +171,7 @@ static int sock_init_common(vrf_id_t vrf_id, const char *name, int *pfd)
}
frr_with_privs(&ospfd_privs) {
- ospf_sock = vrf_socket(AF_INET, SOCK_RAW, IPPROTO_OSPFIGP,
- vrf_id, name);
+ ospf_sock = vrf_socket(AF_INET, SOCK_RAW, proto, vrf_id, name);
if (ospf_sock < 0) {
flog_err(EC_LIB_SOCKET, "%s: socket: %s", __func__,
safe_strerror(errno));
@@ -244,7 +244,8 @@ int ospf_sock_init(struct ospf *ospf)
if (ospf->fd > 0)
return -1;
- ret = sock_init_common(ospf->vrf_id, ospf->name, &(ospf->fd));
+ ret = sock_init_common(ospf->vrf_id, ospf->name, IPPROTO_OSPFIGP,
+ &(ospf->fd));
if (ret >= 0) /* Update socket buffer sizes */
ospf_sock_bufsize_update(ospf, ospf->fd, OSPF_SOCK_BOTH);
@@ -258,8 +259,8 @@ int ospf_sock_init(struct ospf *ospf)
int ospf_ifp_sock_init(struct interface *ifp)
{
struct ospf_if_info *oii;
- struct ospf_interface *oi;
- struct ospf *ospf;
+ struct ospf_interface *oi = NULL;
+ struct ospf *ospf = NULL;
struct route_node *rn;
int ret;
@@ -270,17 +271,26 @@ int ospf_ifp_sock_init(struct interface *ifp)
if (oii->oii_fd > 0)
return 0;
- rn = route_top(IF_OIFS(ifp));
- if (rn && rn->info) {
- oi = rn->info;
- ospf = oi->ospf;
- } else
+ for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
+ if (rn && rn->info) {
+ oi = rn->info;
+ ospf = oi->ospf;
+ break;
+ }
+ }
+
+ if (ospf == NULL)
return -1;
- ret = sock_init_common(ifp->vrf->vrf_id, ifp->name, &oii->oii_fd);
+ ret = sock_init_common(ifp->vrf->vrf_id, ifp->name, IPPROTO_OSPFIGP,
+ &oii->oii_fd);
- if (ret >= 0) /* Update socket buffer sizes */
- ospf_sock_bufsize_update(ospf, oii->oii_fd, OSPF_SOCK_BOTH);
+ if (ret >= 0) { /* Update socket buffer sizes */
+ /* Write-only, so no recv buf */
+ setsockopt_so_recvbuf(oii->oii_fd, 0);
+
+ ospf_sock_bufsize_update(ospf, oii->oii_fd, OSPF_SOCK_SEND);
+ }
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: ifp %s, oii %p, fd %d", __func__, ifp->name,