Merge pull request #13685 from sri-mohan1/srib-ldpd1

ldpd: changes for code maintainability
This commit is contained in:
Donald Sharp 2023-06-05 10:52:46 -04:00 committed by GitHub
commit b107092ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 37 deletions

View File

@ -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);
@ -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
@ -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
@ -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
@ -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

View File

@ -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);
}
@ -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);
}
@ -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;
@ -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");
@ -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");
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}