Skip to content

Commit

Permalink
Merge pull request #13685 from sri-mohan1/srib-ldpd1
Browse files Browse the repository at this point in the history
ldpd: changes for code maintainability
  • Loading branch information
donaldsharp authored Jun 5, 2023
2 parents 4285bda + 233b5d0 commit b107092
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
15 changes: 5 additions & 10 deletions ldpd/ldp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "ldp_debug.h"

static void ifp2kif(struct interface *, struct kif *);
static void ifc2kaddr(struct interface *, struct connected *,
struct kaddr *);
static void ifc2kaddr(struct interface *, struct connected *, struct kaddr *);
static int ldp_zebra_send_mpls_labels(int, struct kroute *);
static int ldp_router_id_update(ZAPI_CALLBACK_ARGS);
static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS);
Expand Down Expand Up @@ -295,8 +294,7 @@ kmpw_add(struct zapi_pw *zpw)
debug_zebra_out("pseudowire %s nexthop %s (add)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));

return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw)
== ZCLIENT_SEND_FAILURE;
return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw) == ZCLIENT_SEND_FAILURE;
}

int
Expand All @@ -305,8 +303,7 @@ kmpw_del(struct zapi_pw *zpw)
debug_zebra_out("pseudowire %s nexthop %s (del)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));

return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw)
== ZCLIENT_SEND_FAILURE;
return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw) == ZCLIENT_SEND_FAILURE;
}

int
Expand All @@ -316,8 +313,7 @@ kmpw_set(struct zapi_pw *zpw)
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop),
zpw->local_label, zpw->remote_label);

return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw)
== ZCLIENT_SEND_FAILURE;
return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw) == ZCLIENT_SEND_FAILURE;
}

int
Expand All @@ -326,8 +322,7 @@ kmpw_unset(struct zapi_pw *zpw)
debug_zebra_out("pseudowire %s nexthop %s (unset)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));

return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw)
== ZCLIENT_SEND_FAILURE;
return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw) == ZCLIENT_SEND_FAILURE;
}

void
Expand Down
42 changes: 15 additions & 27 deletions ldpd/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ ldp_create_socket(int af, enum socket_type type)
return (-1);
}
if (type == LDP_SOCKET_DISC) {
if (sock_set_ipv4_mcast_ttl(fd,
IP_DEFAULT_MULTICAST_TTL) == -1) {
if (sock_set_ipv4_mcast_ttl(fd, IP_DEFAULT_MULTICAST_TTL) == -1) {
close(fd);
return (-1);
}
Expand Down Expand Up @@ -141,7 +140,7 @@ ldp_create_socket(int af, enum socket_type type)
close(fd);
return (-1);
}
if (!(ldpd_conf->ipv6.flags & F_LDPD_AF_NO_GTSM)) {
if (!CHECK_FLAG(ldpd_conf->ipv6.flags, F_LDPD_AF_NO_GTSM)) {
/* ignore any possible error */
sock_set_ipv6_minhopcount(fd, 255);
}
Expand Down Expand Up @@ -171,8 +170,7 @@ ldp_create_socket(int af, enum socket_type type)

#ifdef __OpenBSD__
opt = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt,
sizeof(opt)) == -1) {
if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) {
if (errno == ENOPROTOOPT) { /* system w/o md5sig */
log_warnx("md5sig not available, disabling");
sysdep.no_md5sig = 1;
Expand All @@ -196,7 +194,7 @@ sock_set_nonblock(int fd)
if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
fatal("fcntl F_GETFL");

flags |= O_NONBLOCK;
SET_FLAG(flags, O_NONBLOCK);

if (fcntl(fd, F_SETFL, flags) == -1)
fatal("fcntl F_SETFL");
Expand All @@ -210,7 +208,7 @@ sock_set_cloexec(int fd)
if ((flags = fcntl(fd, F_GETFD, 0)) == -1)
fatal("fcntl F_GETFD");

flags |= FD_CLOEXEC;
SET_FLAG(flags, FD_CLOEXEC);

if (fcntl(fd, F_SETFD, flags) == -1)
fatal("fcntl F_SETFD");
Expand All @@ -222,16 +220,14 @@ sock_set_recvbuf(int fd)
int bsize;

bsize = 65535;
while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize,
sizeof(bsize)) == -1)
while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1)
bsize /= 2;
}

int
sock_set_reuse(int fd, int enable)
{
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable,
sizeof(int)) < 0) {
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting SO_REUSEADDR", __func__);
return (-1);
}
Expand All @@ -244,8 +240,7 @@ sock_set_bindany(int fd, int enable)
{
#ifdef HAVE_SO_BINDANY
frr_with_privs(&ldpd_privs) {
if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable,
sizeof(int)) < 0) {
if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting SO_BINDANY", __func__);
return (-1);
}
Expand All @@ -259,8 +254,7 @@ sock_set_bindany(int fd, int enable)
return (0);
#elif defined(IP_BINDANY)
frr_with_privs(&ldpd_privs) {
if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int))
< 0) {
if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting IP_BINDANY", __func__);
return (-1);
}
Expand Down Expand Up @@ -343,10 +337,8 @@ sock_set_ipv4_ucast_ttl(int fd, int ttl)
int
sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl)
{
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
(char *)&ttl, sizeof(ttl)) < 0) {
log_warn("%s: error setting IP_MULTICAST_TTL to %d",
__func__, ttl);
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) < 0) {
log_warn("%s: error setting IP_MULTICAST_TTL to %d", __func__, ttl);
return (-1);
}

Expand All @@ -358,8 +350,7 @@ sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl)
int
sock_set_ipv4_pktinfo(int fd, int enable)
{
if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable,
sizeof(enable)) < 0) {
if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IP_PKTINFO", __func__);
return (-1);
}
Expand All @@ -370,8 +361,7 @@ sock_set_ipv4_pktinfo(int fd, int enable)
int
sock_set_ipv4_recvdstaddr(int fd, int enable)
{
if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable,
sizeof(enable)) < 0) {
if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IP_RECVDSTADDR", __func__);
return (-1);
}
Expand Down Expand Up @@ -409,8 +399,7 @@ sock_set_ipv4_mcast_loop(int fd)
int
sock_set_ipv6_dscp(int fd, int dscp)
{
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp,
sizeof(dscp)) < 0) {
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) < 0) {
log_warn("%s: error setting IPV6_TCLASS", __func__);
return (-1);
}
Expand All @@ -421,8 +410,7 @@ sock_set_ipv6_dscp(int fd, int dscp)
int
sock_set_ipv6_pktinfo(int fd, int enable)
{
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable,
sizeof(enable)) < 0) {
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IPV6_RECVPKTINFO", __func__);
return (-1);
}
Expand Down

0 comments on commit b107092

Please sign in to comment.