+// SPDX-License-Identifier: GPL-2.0-or-later
/* zebra NETNS ID handling routines
* those routines are implemented locally to avoid having external dependencies.
* Copyright (C) 2018 6WIND
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "vrf.h"
#include "log.h"
#include "lib_errors.h"
+#include "network.h"
#include "zebra/rib.h"
#include "zebra/zebra_dplane.h"
nlh->nlmsg_flags = NLM_F_REQUEST;
if (type == RTM_NEWNSID)
nlh->nlmsg_flags |= NLM_F_ACK;
- nlh->nlmsg_seq = *seq = time(NULL);
+ nlh->nlmsg_seq = *seq = frr_sequence32_next();
return nlh;
}
}
}
- if (ret <= 0) {
- if (errno != EEXIST && ret != 0) {
- flog_err(
- EC_LIB_SOCKET,
- "netlink( %u) recvfrom() error 2 when reading: %s",
- fd, safe_strerror(errno));
- close(sock);
- if (netnspath)
- close(fd);
- if (errno == ENOTSUP) {
- zlog_debug("NEWNSID locally generated");
- return zebra_ns_id_get_fallback(netnspath);
- }
- return NS_UNKNOWN;
- }
- /* message to send to netlink : GETNSID */
- memset(buf, 0, NETLINK_SOCKET_BUFFER_SIZE);
- nlh = initiate_nlh(buf, &seq, RTM_GETNSID);
- rt = (struct rtgenmsg *)(buf + nlh->nlmsg_len);
- nlh->nlmsg_len += NETLINK_ALIGN(sizeof(struct rtgenmsg));
- rt->rtgen_family = AF_UNSPEC;
-
- nl_attr_put32(nlh, NETLINK_SOCKET_BUFFER_SIZE, NETNSA_FD, fd);
- nl_attr_put32(nlh, NETLINK_SOCKET_BUFFER_SIZE, NETNSA_NSID,
- ns_id);
-
- ret = send_receive(sock, nlh, seq, buf);
- if (ret < 0) {
- close(sock);
- if (netnspath)
- close(fd);
- return NS_UNKNOWN;
+ if (errno != EEXIST && ret != 0) {
+ flog_err(EC_LIB_SOCKET,
+ "netlink( %u) recvfrom() error 2 when reading: %s", fd,
+ safe_strerror(errno));
+ close(sock);
+ if (netnspath)
+ close(fd);
+ if (errno == ENOTSUP) {
+ zlog_debug("NEWNSID locally generated");
+ return zebra_ns_id_get_fallback(netnspath);
}
- nlh = (struct nlmsghdr *)buf;
- len = ret;
- ret = 0;
- do {
- if (nlh->nlmsg_type >= NLMSG_MIN_TYPE) {
- return_nsid = extract_nsid(nlh, buf);
- 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)));
- if (err->error < 0)
- errno = -err->error;
- else
- errno = err->error;
- break;
- }
- len = len - NETLINK_ALIGN(nlh->nlmsg_len);
- nlh = (struct nlmsghdr *)((char *)nlh
- + NETLINK_ALIGN(
- nlh->nlmsg_len));
- } while (len != 0 && ret == 0);
+ return NS_UNKNOWN;
}
+ /* message to send to netlink : GETNSID */
+ memset(buf, 0, NETLINK_SOCKET_BUFFER_SIZE);
+ nlh = initiate_nlh(buf, &seq, RTM_GETNSID);
+ rt = (struct rtgenmsg *)(buf + nlh->nlmsg_len);
+ nlh->nlmsg_len += NETLINK_ALIGN(sizeof(struct rtgenmsg));
+ rt->rtgen_family = AF_UNSPEC;
+
+ nl_attr_put32(nlh, NETLINK_SOCKET_BUFFER_SIZE, NETNSA_FD, fd);
+ nl_attr_put32(nlh, NETLINK_SOCKET_BUFFER_SIZE, NETNSA_NSID, ns_id);
+
+ ret = send_receive(sock, nlh, seq, buf);
+ if (ret < 0) {
+ close(sock);
+ if (netnspath)
+ close(fd);
+ return NS_UNKNOWN;
+ }
+ nlh = (struct nlmsghdr *)buf;
+ len = ret;
+ ret = 0;
+ do {
+ if (nlh->nlmsg_type >= NLMSG_MIN_TYPE) {
+ return_nsid = extract_nsid(nlh, buf);
+ 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)));
+ if (err->error < 0)
+ errno = -err->error;
+ else
+ errno = err->error;
+ break;
+ }
+ len = len - NETLINK_ALIGN(nlh->nlmsg_len);
+ nlh = (struct nlmsghdr *)((char *)nlh +
+ NETLINK_ALIGN(nlh->nlmsg_len));
+ } while (len != 0 && ret == 0);
if (netnspath)
close(fd);