]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_network.c
Merge pull request #5280 from qlyoung/doc-clean-topotest-json
[mirror_frr.git] / ospf6d / ospf6_network.c
index 8c2b68fe70146912c143694866f8d48add3c0392..9a18680b8b532c1a2fa16b430c58ab2d9fafeaae 100644 (file)
@@ -73,24 +73,26 @@ static void ospf6_set_checksum(void)
 #endif /* DISABLE_IPV6_CHECKSUM */
 }
 
+void ospf6_serv_close(void)
+{
+       if (ospf6_sock > 0) {
+               close(ospf6_sock);
+               ospf6_sock = -1;
+               return;
+       }
+}
+
 /* Make ospf6d's server socket. */
 int ospf6_serv_sock(void)
 {
-       if (ospf6d_privs.change(ZPRIVS_RAISE))
-               flog_err(LIB_ERR_PRIVILEGES,
-                         "ospf6_serv_sock: could not raise privs");
-
-       ospf6_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_OSPFIGP);
-       if (ospf6_sock < 0) {
-               zlog_warn("Network: can't create OSPF6 socket.");
-               if (ospf6d_privs.change(ZPRIVS_LOWER))
-                       flog_err(LIB_ERR_PRIVILEGES,
-                                 "ospf6_sock_init: could not lower privs");
-               return -1;
+       frr_with_privs(&ospf6d_privs) {
+
+               ospf6_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_OSPFIGP);
+               if (ospf6_sock < 0) {
+                       zlog_warn("Network: can't create OSPF6 socket.");
+                       return -1;
+               }
        }
-       if (ospf6d_privs.change(ZPRIVS_LOWER))
-               flog_err(LIB_ERR_PRIVILEGES,
-                         "ospf6_sock_init: could not lower privs");
 
 /* set socket options */
 #if 1
@@ -124,9 +126,10 @@ int ospf6_sso(ifindex_t ifindex, struct in6_addr *group, int option)
        ret = setsockopt(ospf6_sock, IPPROTO_IPV6, option, &mreq6,
                         sizeof(mreq6));
        if (ret < 0) {
-               flog_err(LIB_ERR_SOCKET,
-                         "Network: setsockopt (%d) on ifindex %d failed: %s",
-                         option, ifindex, safe_strerror(errno));
+               flog_err_sys(
+                       EC_LIB_SOCKET,
+                       "Network: setsockopt (%d) on ifindex %d failed: %s",
+                       option, ifindex, safe_strerror(errno));
                return ret;
        }
 
@@ -169,6 +172,7 @@ int ospf6_sendmsg(struct in6_addr *src, struct in6_addr *dst,
        assert(dst);
        assert(*ifindex);
 
+       memset(&cmsgbuf, 0, sizeof(cmsgbuf));
        scmsgp = (struct cmsghdr *)&cmsgbuf;
        pktinfo = (struct in6_pktinfo *)(CMSG_DATA(scmsgp));
        memset(&dst_sin6, 0, sizeof(struct sockaddr_in6));