diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2018-08-10 18:36:43 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-08-14 22:02:05 +0200 |
commit | 01b9e3fd0d354d7d4c60b1c0240f269a4fd08990 (patch) | |
tree | 7758a10d2c803e86348e04e908f73b63c0048b96 /pimd/pim_sock.c | |
parent | lib: add frr_elevate_privs() wrapper (diff) | |
download | frr-01b9e3fd0d354d7d4c60b1c0240f269a4fd08990.tar.xz frr-01b9e3fd0d354d7d4c60b1c0240f269a4fd08990.zip |
*: use frr_elevate_privs() (1/2: coccinelle)
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'pimd/pim_sock.c')
-rw-r--r-- | pimd/pim_sock.c | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index 976bf3d10..1f584a2f9 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -46,17 +46,11 @@ int pim_socket_raw(int protocol) { int fd; - if (pimd_privs.change(ZPRIVS_RAISE)) - flog_err(LIB_ERR_PRIVILEGES, - "pim_sockek_raw: could not raise privs, %s", - safe_strerror(errno)); + frr_elevate_privs(&pimd_privs) { - fd = socket(AF_INET, SOCK_RAW, protocol); + fd = socket(AF_INET, SOCK_RAW, protocol); - if (pimd_privs.change(ZPRIVS_LOWER)) - flog_err(LIB_ERR_PRIVILEGES, - "pim_socket_raw: could not lower privs, %s", - safe_strerror(errno)); + } if (fd < 0) { zlog_warn("Could not create raw socket: errno=%d: %s", errno, @@ -71,18 +65,13 @@ void pim_socket_ip_hdr(int fd) { const int on = 1; - if (pimd_privs.change(ZPRIVS_RAISE)) - flog_err(LIB_ERR_PRIVILEGES, "%s: could not raise privs, %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + frr_elevate_privs(&pimd_privs) { - if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))) - flog_err_sys(LIB_ERR_SOCKET, - "%s: Could not turn on IP_HDRINCL option: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))) + zlog_err("%s: Could not turn on IP_HDRINCL option: %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); - if (pimd_privs.change(ZPRIVS_LOWER)) - flog_err(LIB_ERR_PRIVILEGES, "%s: could not lower privs, %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + } } /* @@ -94,16 +83,12 @@ int pim_socket_bind(int fd, struct interface *ifp) int ret = 0; #ifdef SO_BINDTODEVICE - if (pimd_privs.change(ZPRIVS_RAISE)) - flog_err(LIB_ERR_PRIVILEGES, "%s: could not raise privs, %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + frr_elevate_privs(&pimd_privs) { - ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifp->name, - strlen(ifp->name)); + ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifp->name, + strlen(ifp->name)); - if (pimd_privs.change(ZPRIVS_LOWER)) - flog_err(LIB_ERR_PRIVILEGES, "%s: could not lower privs, %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + } #endif return ret; |