{
struct ifreq ifr;
- strncpy(ifr.ifr_name, iface, IFNAMSIZ);
+ strncpy(ifr.ifr_name, iface, IFNAMSIZ - 1);
if (ioctl(nhrp_socket_fd, SIOCGIFFLAGS, &ifr))
return -1;
extern int netlink_nflog_group;
extern int netlink_req_fd;
-int netlink_init(void);
+void netlink_init(void);
int netlink_configure_arp(unsigned int ifindex, int pf);
void netlink_update_binding(struct interface *ifp, union sockunion *proto, union sockunion *nbma);
void netlink_set_nflog_group(int nlgroup);
netlink_nflog_group = nlgroup;
if (nlgroup) {
netlink_log_fd = znl_open(NETLINK_NETFILTER, 0);
+ if (netlink_log_fd < 0)
+ return;
+
netlink_log_register(netlink_log_fd, nlgroup);
thread_add_read(master, netlink_log_recv, 0, netlink_log_fd,
&netlink_log_thread);
}
}
-int netlink_init(void)
+void netlink_init(void)
{
netlink_req_fd = znl_open(NETLINK_ROUTE, 0);
+ if (netlink_req_fd < 0)
+ return;
+
netlink_listen_fd = znl_open(NETLINK_ROUTE, RTMGRP_NEIGH);
+ if (netlink_listen_fd < 0)
+ return;
+
thread_add_read(master, netlink_route_recv, 0, netlink_listen_fd,
NULL);
-
- return 0;
}
int netlink_configure_arp(unsigned int ifindex, int pf)
buf[len] = 0;
debugf(NHRP_DEBUG_EVENT, "evmgr: msg: %s", buf);
- sscanf(buf, "eventid=%d", &eventid);
- sscanf(buf, "result=%63s", result);
+ if (sscanf(buf, "eventid=%d", &eventid) != 1)
+ continue;
+ if (sscanf(buf, "result=%63s", result) != 1)
+ continue;
}
debugf(NHRP_DEBUG_EVENT, "evmgr: received: eventid=%d result=%s", eventid, result);
if (eventid && result[0]) {
const char *name;
void (*handler)(struct nhrp_packet_parser *);
} packet_types[] = {
+ [0] = {
+ .type = PACKET_UNKNOWN,
+ .name = "UNKNOWN",
+ },
[NHRP_PACKET_RESOLUTION_REQUEST] = {
.type = PACKET_REQUEST,
.name = "Resolution-Request",
nbma_afi = htons(hdr->afnum);
proto_afi = proto2afi(htons(hdr->protocol_type));
- if (hdr->type > ZEBRA_NUM_OF(packet_types) ||
+ if (hdr->type > NHRP_PACKET_MAX ||
hdr->version != NHRP_VERSION_RFC2332 ||
nbma_afi >= AFI_MAX || proto_afi == AF_UNSPEC ||
packet_types[hdr->type].type == PACKET_UNKNOWN ||
#define NHRP_PACKET_PURGE_REPLY 6
#define NHRP_PACKET_ERROR_INDICATION 7
#define NHRP_PACKET_TRAFFIC_INDICATION 8
+#define NHRP_PACKET_MAX 8
/* NHRP Extension Types */
#define NHRP_EXTENSION_FLAG_COMPULSORY 0x8000
if (ret == NHRP_OK)
return CMD_SUCCESS;
- if (ret > 0 && ret <= (int)ZEBRA_NUM_OF(errmsgs))
+ if (ret > 0 && ret <= NHRP_ERR_MAX)
if (errmsgs[ret])
str = errmsgs[ret];
NHRP_ERR_ENTRY_EXISTS,
NHRP_ERR_ENTRY_NOT_FOUND,
NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH,
+ __NHRP_ERR_MAX
};
+#define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
struct notifier_block;
case 'l':
if (blob_equal(key, "local-host") && ctx->nsections == 1) {
if (blob2buf(val, buf, sizeof(buf)))
- str2sockunion(buf, &sactx->local.host);
+ if (str2sockunion(buf, &sactx->local.host) < 0)
+ zlog_err("VICI: bad strongSwan local-host: %s", buf);
} else if (blob_equal(key, "local-id") && ctx->nsections == 1) {
sactx->local.id = *val;
} else if (blob_equal(key, "local-cert-data") && ctx->nsections == 1) {
case 'r':
if (blob_equal(key, "remote-host") && ctx->nsections == 1) {
if (blob2buf(val, buf, sizeof(buf)))
- str2sockunion(buf, &sactx->remote.host);
+ if (str2sockunion(buf, &sactx->remote.host) < 0)
+ zlog_err("VICI: bad strongSwan remote-host: %s", buf);
} else if (blob_equal(key, "remote-id") && ctx->nsections == 1) {
sactx->remote.id = *val;
} else if (blob_equal(key, "remote-cert-data") && ctx->nsections == 1) {
uint32_t msglen;
uint8_t msgtype;
struct blob name;
+ struct vici_message_ctx ctx;
msglen = zbuf_get_be32(msg);
msgtype = zbuf_get8(msg);
vici_recv_sa(vici, msg, 2);
break;
case VICI_CMD_RESPONSE:
- vici_parse_message(vici, msg, parse_cmd_response, 0);
+ vici_parse_message(vici, msg, parse_cmd_response, &ctx);
break;
case VICI_EVENT_UNKNOWN:
case VICI_CMD_UNKNOWN:
zbuf_put_be16(obuf, len);
zbuf_put(obuf, va_arg(va, void *), len);
break;
- case VICI_END:
- break;
default:
break;
}
memset(&addr, 0, sizeof (struct sockaddr_un));
addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, path, strlen (path));
+ strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
ret = connect(fd, (struct sockaddr *) &addr, sizeof(addr.sun_family) + strlen(addr.sun_path));
if (ret < 0) {
return -1;
}
- fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+ ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
return fd;
}
if (fd < 0)
return -1;
- fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
- fcntl(fd, F_SETFD, FD_CLOEXEC);
+ if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) < 0)
+ goto error;
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto error;
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf, sizeof(buf)) < 0)
goto error;