summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_netns_id.c
diff options
context:
space:
mode:
authorLou Berger <lberger@labn.net>2018-03-06 20:02:52 +0100
committerLou Berger <lberger@labn.net>2018-03-06 20:04:32 +0100
commit996c93142d3abfab0f6d6c800474e22a8cfbdbc5 (patch)
tree2b28846d256c84cf7b7f1a8988fb3267c8611722 /zebra/zebra_netns_id.c
parentbgpd: another change to keep indent.py happy (diff)
downloadfrr-996c93142d3abfab0f6d6c800474e22a8cfbdbc5.tar.xz
frr-996c93142d3abfab0f6d6c800474e22a8cfbdbc5.zip
*: conform with COMMUNITY.md formatting rules, via 'make indent'
Signed-off-by: Lou Berger <lberger@labn.net>
Diffstat (limited to 'zebra/zebra_netns_id.c')
-rw-r--r--zebra/zebra_netns_id.c93
1 files changed, 48 insertions, 45 deletions
diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c
index 966d6ed0d..a81413f5a 100644
--- a/zebra/zebra_netns_id.c
+++ b/zebra/zebra_netns_id.c
@@ -47,8 +47,8 @@
#define NETLINK_SOCKET_BUFFER_SIZE 512
#define NETLINK_ALIGNTO 4
-#define NETLINK_ALIGN(len) (((len)+NETLINK_ALIGNTO-1) \
- & ~(NETLINK_ALIGNTO-1))
+#define NETLINK_ALIGN(len) \
+ (((len) + NETLINK_ALIGNTO - 1) & ~(NETLINK_ALIGNTO - 1))
#define NETLINK_NLATTR_LEN(_a, _b) (unsigned int)((char *)_a - (char *)_b)
#endif /* defined(HAVE_NETLINK) */
@@ -77,36 +77,33 @@ static struct nlmsghdr *initiate_nlh(char *buf, unsigned int *seq, int type)
return nlh;
}
-static int send_receive(int sock, struct nlmsghdr *nlh,
- unsigned int seq, char *buf)
+static int send_receive(int sock, struct nlmsghdr *nlh, unsigned int seq,
+ char *buf)
{
int ret;
- static const struct sockaddr_nl snl = {
- .nl_family = AF_NETLINK
- };
+ static const struct sockaddr_nl snl = {.nl_family = AF_NETLINK};
ret = sendto(sock, (const void *)nlh, (size_t)nlh->nlmsg_len, 0,
- (struct sockaddr *) &snl, (socklen_t)sizeof(snl));
+ (struct sockaddr *)&snl, (socklen_t)sizeof(snl));
if (ret < 0) {
- zlog_err("netlink( %u) sendmsg() error: %s",
- sock, safe_strerror(errno));
+ zlog_err("netlink( %u) sendmsg() error: %s", sock,
+ safe_strerror(errno));
return -1;
}
/* reception */
struct sockaddr_nl addr;
struct iovec iov = {
- .iov_base = buf,
- .iov_len = NETLINK_SOCKET_BUFFER_SIZE,
+ .iov_base = buf, .iov_len = NETLINK_SOCKET_BUFFER_SIZE,
};
struct msghdr msg = {
- .msg_name = &addr,
- .msg_namelen = sizeof(struct sockaddr_nl),
- .msg_iov = &iov,
- .msg_iovlen = 1,
- .msg_control = NULL,
+ .msg_name = &addr,
+ .msg_namelen = sizeof(struct sockaddr_nl),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = NULL,
.msg_controllen = 0,
- .msg_flags = 0,
+ .msg_flags = 0,
};
ret = recvmsg(sock, &msg, 0);
if (ret < 0) {
@@ -119,8 +116,9 @@ static int send_receive(int sock, struct nlmsghdr *nlh,
}
/* nlh already points to buf */
if (nlh->nlmsg_seq != seq) {
- zlog_err("netlink recvmsg: bad sequence number %x (expected %x)",
- seq, nlh->nlmsg_seq);
+ zlog_err(
+ "netlink recvmsg: bad sequence number %x (expected %x)",
+ seq, nlh->nlmsg_seq);
return -1;
}
return ret;
@@ -132,16 +130,16 @@ static int send_receive(int sock, struct nlmsghdr *nlh,
static ns_id_t extract_nsid(struct nlmsghdr *nlh, char *buf)
{
ns_id_t ns_id = NS_UNKNOWN;
- int offset = NETLINK_ALIGN(sizeof(struct nlmsghdr)) +
- NETLINK_ALIGN(sizeof(struct rtgenmsg));
+ int offset = NETLINK_ALIGN(sizeof(struct nlmsghdr))
+ + NETLINK_ALIGN(sizeof(struct rtgenmsg));
int curr_length = offset;
void *tail = (void *)((char *)nlh + NETLINK_ALIGN(nlh->nlmsg_len));
struct nlattr *attr;
for (attr = (struct nlattr *)((char *)buf + offset);
- NETLINK_NLATTR_LEN(tail, attr) >= sizeof(struct nlattr) &&
- attr->nla_len >= sizeof(struct nlattr) &&
- attr->nla_len <= NETLINK_NLATTR_LEN(tail, attr);
+ NETLINK_NLATTR_LEN(tail, attr) >= sizeof(struct nlattr)
+ && attr->nla_len >= sizeof(struct nlattr)
+ && attr->nla_len <= NETLINK_NLATTR_LEN(tail, attr);
attr += NETLINK_ALIGN(attr->nla_len)) {
curr_length += attr->nla_len;
if ((attr->nla_type & NLA_TYPE_MASK) == NETNSA_NSID) {
@@ -172,8 +170,8 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
/* netlink socket */
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0) {
- zlog_err("netlink( %u) socket() error: %s",
- sock, safe_strerror(errno));
+ zlog_err("netlink( %u) socket() error: %s", sock,
+ safe_strerror(errno));
return NS_UNKNOWN;
}
memset(&snl, 0, sizeof(snl));
@@ -182,8 +180,8 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
snl.nl_pid = 0; /* AUTO PID */
ret = bind(sock, (struct sockaddr *)&snl, sizeof(snl));
if (ret < 0) {
- zlog_err("netlink( %u) socket() bind error: %s",
- sock, safe_strerror(errno));
+ zlog_err("netlink( %u) socket() bind error: %s", sock,
+ safe_strerror(errno));
close(sock);
close(fd);
return NS_UNKNOWN;
@@ -222,10 +220,12 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
break;
} else {
if (nlh->nlmsg_type == NLMSG_ERROR) {
- struct nlmsgerr *err = (struct nlmsgerr *)
- ((char *)nlh +
- NETLINK_ALIGN(sizeof(
- struct nlmsghdr)));
+ struct nlmsgerr *err =
+ (struct nlmsgerr
+ *)((char *)nlh
+ + NETLINK_ALIGN(sizeof(
+ struct
+ nlmsghdr)));
ret = -1;
if (err->error < 0)
@@ -248,14 +248,15 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
}
}
len = len - NETLINK_ALIGN(nlh->nlmsg_len);
- nlh = (struct nlmsghdr *)((char *)nlh +
- NETLINK_ALIGN(nlh->nlmsg_len));
+ nlh = (struct nlmsghdr *)((char *)nlh
+ + NETLINK_ALIGN(nlh->nlmsg_len));
} while (len != 0 && return_nsid != NS_UNKNOWN && ret == 0);
if (ret <= 0) {
if (errno != EEXIST && ret != 0) {
- zlog_err("netlink( %u) recvfrom() error 2 when reading: %s",
- fd, safe_strerror(errno));
+ zlog_err(
+ "netlink( %u) recvfrom() error 2 when reading: %s",
+ fd, safe_strerror(errno));
close(sock);
close(fd);
if (errno == ENOTSUP) {
@@ -289,10 +290,12 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
if (return_nsid != NS_UNKNOWN)
break;
} else if (nlh->nlmsg_type == NLMSG_ERROR) {
- struct nlmsgerr *err = (struct nlmsgerr *)
- ((char *)nlh +
- NETLINK_ALIGN(sizeof(
- struct nlmsghdr)));
+ struct nlmsgerr *err =
+ (struct nlmsgerr
+ *)((char *)nlh
+ + NETLINK_ALIGN(sizeof(
+ struct
+ nlmsghdr)));
if (err->error < 0)
errno = -err->error;
else
@@ -300,8 +303,9 @@ ns_id_t zebra_ns_id_get(const char *netnspath)
break;
}
len = len - NETLINK_ALIGN(nlh->nlmsg_len);
- nlh = (struct nlmsghdr *)((char *)nlh +
- NETLINK_ALIGN(nlh->nlmsg_len));
+ nlh = (struct nlmsghdr *)((char *)nlh
+ + NETLINK_ALIGN(
+ nlh->nlmsg_len));
} while (len != 0 && return_nsid != NS_UNKNOWN && ret == 0);
}
@@ -348,8 +352,7 @@ ns_id_t zebra_ns_id_get_default(void)
return NS_DEFAULT_INTERNAL;
close(fd);
return zebra_ns_id_get((char *)NS_DEFAULT_NAME);
-#else /* HAVE_NETNS */
+#else /* HAVE_NETNS */
return NS_DEFAULT_INTERNAL;
#endif /* !HAVE_NETNS */
}
-