1999-12-16 13:06:13 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Linux Multicasting and Network Includes
|
|
|
|
*
|
2000-04-20 23:05:41 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1999-12-16 13:06:13 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2024-02-05 13:43:46 +00:00
|
|
|
#include "sysdep/linux/tcp-ao.h"
|
|
|
|
|
2024-02-07 13:52:31 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
#ifndef IPV6_MINHOPCOUNT
|
|
|
|
#define IPV6_MINHOPCOUNT 73
|
|
|
|
#endif
|
1999-12-16 13:06:13 +00:00
|
|
|
|
2022-01-08 17:31:56 +00:00
|
|
|
#ifndef IPV6_FREEBIND
|
|
|
|
#define IPV6_FREEBIND 78
|
|
|
|
#endif
|
|
|
|
|
2020-02-27 15:16:48 +00:00
|
|
|
#ifndef TCP_MD5SIG_EXT
|
|
|
|
#define TCP_MD5SIG_EXT 32
|
|
|
|
#endif
|
2009-09-04 09:06:51 +00:00
|
|
|
|
2020-02-27 15:16:48 +00:00
|
|
|
#ifndef TCP_MD5SIG_FLAG_PREFIX
|
|
|
|
#define TCP_MD5SIG_FLAG_PREFIX 1
|
|
|
|
#endif
|
2009-09-04 09:06:51 +00:00
|
|
|
|
2024-02-05 13:43:46 +00:00
|
|
|
#ifndef TCP_AO_ADD_KEY
|
|
|
|
#define TCP_AO_ADD_KEY 38 /* Add/Set MKT */
|
|
|
|
#define TCP_AO_DEL_KEY 39 /* Delete MKT */
|
|
|
|
#define TCP_AO_INFO 40 /* Set/list TCP-AO per-socket options */
|
|
|
|
#define TCP_AO_GET_KEYS 41 /* List MKT(s) */
|
|
|
|
#define TCP_AO_REPAIR 42 /* Get/Set SNEs and ISNs */
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-02-27 15:16:48 +00:00
|
|
|
/* We redefine the tcp_md5sig structure with different name to avoid collision with older headers */
|
|
|
|
struct tcp_md5sig_ext {
|
|
|
|
struct sockaddr_storage tcpm_addr; /* Address associated */
|
|
|
|
u8 tcpm_flags; /* Extension flags */
|
|
|
|
u8 tcpm_prefixlen; /* Address prefix */
|
|
|
|
u16 tcpm_keylen; /* Key length */
|
|
|
|
u32 __tcpm_pad2; /* Zero */
|
|
|
|
u8 tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary) */
|
2014-05-18 09:42:26 +00:00
|
|
|
};
|
2009-09-04 09:06:51 +00:00
|
|
|
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
/* Linux does not care if sa_len is larger than needed */
|
|
|
|
#define SA_LEN(x) sizeof(sockaddr)
|
2009-09-04 09:06:51 +00:00
|
|
|
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
/*
|
|
|
|
* Linux IPv4 multicast syscalls
|
|
|
|
*/
|
2009-09-04 09:06:51 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
#define INIT_MREQ4(maddr,ifa) \
|
|
|
|
{ .imr_multiaddr = ipa_to_in4(maddr), .imr_ifindex = ifa->index }
|
1999-12-16 13:06:13 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_setup_multicast4(sock *s)
|
|
|
|
{
|
|
|
|
struct ip_mreqn mr = { .imr_ifindex = s->iface->index };
|
|
|
|
int ttl = s->ttl;
|
|
|
|
int n = 0;
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
/* This defines where should we send _outgoing_ multicasts */
|
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &mr, sizeof(mr)) < 0)
|
|
|
|
ERR("IP_MULTICAST_IF");
|
2009-09-04 09:06:51 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
|
|
|
|
ERR("IP_MULTICAST_TTL");
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_LOOP, &n, sizeof(n)) < 0)
|
|
|
|
ERR("IP_MULTICAST_LOOP");
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_join_group4(sock *s, ip_addr maddr)
|
|
|
|
{
|
|
|
|
struct ip_mreqn mr = INIT_MREQ4(maddr, s->iface);
|
2014-03-31 11:21:13 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0)
|
|
|
|
ERR("IP_ADD_MEMBERSHIP");
|
2008-10-26 21:42:39 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-04 16:17:46 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_leave_group4(sock *s, ip_addr maddr)
|
2009-05-04 16:17:46 +00:00
|
|
|
{
|
2014-05-18 09:42:26 +00:00
|
|
|
struct ip_mreqn mr = INIT_MREQ4(maddr, s->iface);
|
2009-05-04 16:17:46 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &mr, sizeof(mr)) < 0)
|
|
|
|
ERR("IP_DROP_MEMBERSHIP");
|
2009-05-04 16:17:46 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
2009-05-04 16:17:46 +00:00
|
|
|
}
|
2010-02-11 09:23:35 +00:00
|
|
|
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
/*
|
|
|
|
* Linux IPv4 packet control messages
|
|
|
|
*/
|
2010-02-11 09:23:35 +00:00
|
|
|
|
|
|
|
/* Mostly similar to standardized IPv6 code */
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
#define CMSG4_SPACE_PKTINFO CMSG_SPACE(sizeof(struct in_pktinfo))
|
|
|
|
#define CMSG4_SPACE_TTL CMSG_SPACE(sizeof(int))
|
2010-02-11 09:23:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_request_cmsg4_pktinfo(sock *s)
|
2010-02-11 09:23:35 +00:00
|
|
|
{
|
2014-05-18 09:42:26 +00:00
|
|
|
int y = 1;
|
2013-06-25 13:33:00 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_PKTINFO, &y, sizeof(y)) < 0)
|
|
|
|
ERR("IP_PKTINFO");
|
2010-02-11 09:23:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
2010-02-11 09:23:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_request_cmsg4_ttl(sock *s)
|
2010-02-11 09:23:35 +00:00
|
|
|
{
|
2014-05-18 09:42:26 +00:00
|
|
|
int y = 1;
|
2010-02-11 09:23:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_RECVTTL, &y, sizeof(y)) < 0)
|
|
|
|
ERR("IP_RECVTTL");
|
2013-06-25 13:33:00 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-06-25 13:33:00 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline void
|
|
|
|
sk_process_cmsg4_pktinfo(sock *s, struct cmsghdr *cm)
|
|
|
|
{
|
|
|
|
if (cm->cmsg_type == IP_PKTINFO)
|
2013-06-25 13:33:00 +00:00
|
|
|
{
|
2014-05-18 09:42:26 +00:00
|
|
|
struct in_pktinfo *pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
|
|
|
s->laddr = ipa_from_in4(pi->ipi_addr);
|
|
|
|
s->lifindex = pi->ipi_ifindex;
|
2013-06-25 13:33:00 +00:00
|
|
|
}
|
2014-05-18 09:42:26 +00:00
|
|
|
}
|
2013-06-25 13:33:00 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline void
|
|
|
|
sk_process_cmsg4_ttl(sock *s, struct cmsghdr *cm)
|
|
|
|
{
|
|
|
|
if (cm->cmsg_type == IP_TTL)
|
|
|
|
s->rcv_ttl = * (int *) CMSG_DATA(cm);
|
2010-02-11 09:23:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline void
|
|
|
|
sk_prepare_cmsgs4(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
|
2010-02-11 09:23:35 +00:00
|
|
|
{
|
|
|
|
struct cmsghdr *cm;
|
|
|
|
struct in_pktinfo *pi;
|
2014-06-26 11:30:27 +00:00
|
|
|
int controllen = 0;
|
2010-02-11 09:23:35 +00:00
|
|
|
|
2010-04-02 09:31:20 +00:00
|
|
|
msg->msg_control = cbuf;
|
|
|
|
msg->msg_controllen = cbuflen;
|
2010-02-11 09:23:35 +00:00
|
|
|
|
|
|
|
cm = CMSG_FIRSTHDR(msg);
|
2014-02-06 16:46:01 +00:00
|
|
|
cm->cmsg_level = SOL_IP;
|
2010-02-11 09:23:35 +00:00
|
|
|
cm->cmsg_type = IP_PKTINFO;
|
|
|
|
cm->cmsg_len = CMSG_LEN(sizeof(*pi));
|
2014-06-26 11:30:27 +00:00
|
|
|
controllen += CMSG_SPACE(sizeof(*pi));
|
2010-02-11 09:23:35 +00:00
|
|
|
|
|
|
|
pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
|
|
|
pi->ipi_ifindex = s->iface ? s->iface->index : 0;
|
2014-05-18 09:42:26 +00:00
|
|
|
pi->ipi_spec_dst = ipa_to_in4(s->saddr);
|
|
|
|
pi->ipi_addr = ipa_to_in4(IPA_NONE);
|
2010-02-11 09:23:35 +00:00
|
|
|
|
2014-06-26 11:30:27 +00:00
|
|
|
msg->msg_controllen = controllen;
|
2010-02-11 09:23:35 +00:00
|
|
|
}
|
2014-02-06 16:46:01 +00:00
|
|
|
|
2010-04-07 21:15:56 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
/*
|
|
|
|
* Miscellaneous Linux socket syscalls
|
|
|
|
*/
|
|
|
|
int
|
2024-02-14 12:48:08 +00:00
|
|
|
sk_set_md5_auth(sock *s, ip_addr local UNUSED, ip_addr remote, int pxlen, struct iface *ifa, const char *passwd, int setkey UNUSED)
|
2014-05-18 09:42:26 +00:00
|
|
|
{
|
2020-02-27 15:16:48 +00:00
|
|
|
struct tcp_md5sig_ext md5;
|
2024-02-14 12:48:08 +00:00
|
|
|
log("md5 password is %i, socket fd %i", passwd, s->fd);
|
2011-08-16 21:05:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
memset(&md5, 0, sizeof(md5));
|
2016-04-13 12:30:28 +00:00
|
|
|
sockaddr_fill((sockaddr *) &md5.tcpm_addr, s->af, remote, ifa, 0);
|
2011-08-16 21:05:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (passwd)
|
|
|
|
{
|
|
|
|
int len = strlen(passwd);
|
|
|
|
|
|
|
|
if (len > TCP_MD5SIG_MAXKEYLEN)
|
2016-04-13 12:30:28 +00:00
|
|
|
ERR_MSG("The password for TCP MD5 Signature is too long");
|
2011-08-16 21:05:35 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
md5.tcpm_keylen = len;
|
|
|
|
memcpy(&md5.tcpm_key, passwd, len);
|
|
|
|
}
|
|
|
|
|
2024-02-05 13:43:46 +00:00
|
|
|
if (pxlen < 0)
|
|
|
|
{
|
2024-02-14 12:48:08 +00:00
|
|
|
if (setsockopt(s->fd, SOL_TCP, TCP_MD5SIG_EXT, &md5, sizeof(md5)) < 0)
|
2024-02-05 13:43:46 +00:00
|
|
|
if (errno == ENOPROTOOPT)
|
|
|
|
ERR_MSG("Kernel does not support TCP MD5 signatures");
|
|
|
|
else
|
2024-02-14 12:48:08 +00:00
|
|
|
ERR("TCP_MD5SIG");
|
2024-02-05 13:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
md5.tcpm_flags = TCP_MD5SIG_FLAG_PREFIX;
|
|
|
|
md5.tcpm_prefixlen = pxlen;
|
|
|
|
|
|
|
|
if (setsockopt(s->fd, SOL_TCP, TCP_MD5SIG_EXT, &md5, sizeof(md5)) < 0)
|
|
|
|
{
|
|
|
|
if (errno == ENOPROTOOPT)
|
|
|
|
ERR_MSG("Kernel does not support extended TCP MD5 signatures");
|
|
|
|
else
|
|
|
|
ERR("TCP_MD5SIG_EXT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-14 12:48:08 +00:00
|
|
|
void log_tcp_ao_info(int sock_fd)
|
2024-02-05 13:43:46 +00:00
|
|
|
{
|
2024-02-14 12:48:08 +00:00
|
|
|
struct tcp_ao_info_opt_ext tmp;
|
|
|
|
memset(&tmp, 0, sizeof(struct tcp_ao_info_opt_ext));
|
|
|
|
socklen_t len = sizeof(tmp);
|
|
|
|
log("socket: fd %i", sock_fd);
|
2024-02-05 13:43:46 +00:00
|
|
|
|
2024-02-14 12:48:08 +00:00
|
|
|
if (getsockopt(sock_fd, IPPROTO_TCP, TCP_AO_INFO, &tmp, &len))
|
2024-02-05 13:43:46 +00:00
|
|
|
{
|
2024-02-14 12:48:08 +00:00
|
|
|
log("log tcp ao info failed with err code %i", errno);
|
|
|
|
return;
|
2024-02-05 13:43:46 +00:00
|
|
|
}
|
2024-02-14 12:48:08 +00:00
|
|
|
else
|
2024-02-19 11:09:36 +00:00
|
|
|
log("current key id %i, next key %i,\n set current %i, ao required %i\n good packets %i, bad packets %i",
|
|
|
|
tmp.current_key, tmp.rnext, tmp.set_current, tmp.ao_required, tmp.pkt_good, tmp.pkt_bad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
log_tcp_ao_get_key(int sock_fd)
|
|
|
|
{
|
|
|
|
struct tcp_ao_getsockopt_ext tmp;
|
|
|
|
memset(&tmp, 0, sizeof(struct tcp_ao_getsockopt_ext));
|
|
|
|
socklen_t len = sizeof(tmp);
|
|
|
|
tmp.nkeys = 1;
|
|
|
|
tmp.get_all = 1;
|
|
|
|
|
|
|
|
if (getsockopt(sock_fd, IPPROTO_TCP, TCP_AO_GET_KEYS, &tmp, &len))
|
|
|
|
{
|
|
|
|
log("log tcp ao get keys failed with err code %i", errno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log("cipher %s key %s num of keys %i", tmp.alg_name, tmp.key, tmp.nkeys);
|
|
|
|
|
2024-02-14 12:48:08 +00:00
|
|
|
}
|
2024-02-05 13:43:46 +00:00
|
|
|
|
2024-02-14 12:48:08 +00:00
|
|
|
int
|
2024-02-19 11:09:36 +00:00
|
|
|
sk_set_ao_auth(sock *s, ip_addr local, ip_addr remote, int pxlen, struct iface *ifa, const char *passwd, int passwd_id_loc, int passwd_id_rem, const char* cipher)
|
2024-02-14 12:48:08 +00:00
|
|
|
{
|
|
|
|
struct tcp_ao_add_ext ao;
|
|
|
|
memset(&ao, 0, sizeof(struct tcp_ao_add_ext));
|
2024-02-19 11:09:36 +00:00
|
|
|
log("in sk set ao");
|
|
|
|
log("%s %i %i", passwd, passwd_id_loc, passwd_id_rem);
|
2024-02-14 12:48:08 +00:00
|
|
|
log("af %i %I %I (%i or %i) %s %i", s->af, remote, local, AF_INET, AF_INET6, passwd, passwd[0]);
|
|
|
|
/* int af;
|
|
|
|
if (ipa_is_ip4(remote))
|
|
|
|
af = AF_INET;
|
2020-02-27 15:16:48 +00:00
|
|
|
else
|
2024-02-14 12:48:08 +00:00
|
|
|
af = AF_INET6;*/
|
|
|
|
sockaddr_fill((sockaddr *) &ao.addr, s->af, remote, ifa, 0);
|
|
|
|
ao.set_current = 0;
|
|
|
|
ao.set_rnext = 0;
|
|
|
|
if (pxlen >= 0)
|
|
|
|
ao.prefix = pxlen;
|
|
|
|
else if(s->af == AF_INET)
|
|
|
|
ao.prefix = 32;
|
|
|
|
else
|
|
|
|
ao.prefix = 128;
|
|
|
|
ao.sndid = passwd_id_rem;
|
|
|
|
ao.rcvid = passwd_id_loc;
|
|
|
|
ao.maclen = 0;
|
|
|
|
ao.keyflags = 0;
|
|
|
|
ao.ifindex = 0;
|
|
|
|
|
2024-02-19 11:09:36 +00:00
|
|
|
strncpy(ao.alg_name, (cipher) ? cipher : DEFAULT_TEST_ALGO, 64);
|
2024-02-14 12:48:08 +00:00
|
|
|
|
|
|
|
ao.keylen = strlen(passwd);
|
|
|
|
memcpy(ao.key, passwd, (strlen(passwd) > TCP_AO_MAXKEYLEN_) ? TCP_AO_MAXKEYLEN_ : strlen(passwd));
|
|
|
|
|
|
|
|
int IPPROTO_TCP_ = 6;
|
|
|
|
if (setsockopt(s->fd, IPPROTO_TCP, TCP_AO_ADD_KEY, &ao, sizeof(ao)) < 0)
|
|
|
|
bug("tcp ao err %i", errno);
|
|
|
|
|
|
|
|
log_tcp_ao_info(s->fd);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-27 15:16:48 +00:00
|
|
|
|
2024-02-19 11:09:36 +00:00
|
|
|
void
|
|
|
|
ao_try_change_master(int sock_fd, int next_master_id )
|
|
|
|
{
|
|
|
|
struct tcp_ao_info_opt_ext tmp;
|
|
|
|
memset(&tmp, 0, sizeof(struct tcp_ao_info_opt_ext));
|
|
|
|
socklen_t len = sizeof(tmp);
|
|
|
|
tmp.set_rnext = 1;
|
|
|
|
tmp.rnext = next_master_id;
|
|
|
|
|
|
|
|
if (setsockopt(sock_fd, IPPROTO_TCP, TCP_AO_INFO, &tmp, &len))
|
|
|
|
{
|
|
|
|
log(" tcp ao change master key failed with err code %i", errno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log("tried to change master");
|
|
|
|
}
|
|
|
|
|
2024-02-14 12:48:08 +00:00
|
|
|
void
|
|
|
|
save_to_repair(int sock_fd)
|
|
|
|
{
|
|
|
|
struct tcp_ao_repair_ext replace_me; //TODO not ignore replace_me
|
|
|
|
socklen_t len = sizeof(replace_me);
|
|
|
|
memset(&replace_me, 0, sizeof(struct tcp_ao_repair_ext));
|
|
|
|
if (getsockopt(sock_fd, IPPROTO_TCP, TCP_AO_REPAIR, &replace_me, &len) < 0)
|
|
|
|
bug("geting tcp ao img not succeed %i", errno);
|
|
|
|
log("got tcp ao img");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
repair_tcp_ao(int sock_fd, struct iface *ifa)
|
|
|
|
{
|
|
|
|
//if (setsockopt(sock_fd, SOL_TCP, TCP_AO_REPAIR, &ifa->tcp_ao_img, sizeof(ifa->tcp_ao_img)) < 0)
|
|
|
|
// bug("tcp ao err %i", errno);
|
|
|
|
log("tcp ao repair skiped");
|
|
|
|
}
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
2011-08-16 21:05:35 +00:00
|
|
|
sk_set_min_ttl4(sock *s, int ttl)
|
|
|
|
{
|
2014-02-06 16:46:01 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_MINTTL, &ttl, sizeof(ttl)) < 0)
|
2011-08-16 21:05:35 +00:00
|
|
|
{
|
|
|
|
if (errno == ENOPROTOOPT)
|
2014-05-18 09:42:26 +00:00
|
|
|
ERR_MSG("Kernel does not support IPv4 TTL security");
|
2011-08-16 21:05:35 +00:00
|
|
|
else
|
2014-05-18 09:42:26 +00:00
|
|
|
ERR("IP_MINTTL");
|
2011-08-16 21:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
2011-08-16 21:05:35 +00:00
|
|
|
sk_set_min_ttl6(sock *s, int ttl)
|
|
|
|
{
|
2014-02-06 16:46:01 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IPV6, IPV6_MINHOPCOUNT, &ttl, sizeof(ttl)) < 0)
|
2011-08-16 21:05:35 +00:00
|
|
|
{
|
|
|
|
if (errno == ENOPROTOOPT)
|
2014-05-18 09:42:26 +00:00
|
|
|
ERR_MSG("Kernel does not support IPv6 TTL security");
|
2011-08-16 21:05:35 +00:00
|
|
|
else
|
2014-05-18 09:42:26 +00:00
|
|
|
ERR("IPV6_MINHOPCOUNT");
|
2011-08-16 21:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
|
|
|
sk_disable_mtu_disc4(sock *s)
|
|
|
|
{
|
|
|
|
int dont = IP_PMTUDISC_DONT;
|
2013-06-24 14:37:30 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_MTU_DISCOVER, &dont, sizeof(dont)) < 0)
|
|
|
|
ERR("IP_MTU_DISCOVER");
|
2013-06-24 14:37:30 +00:00
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
sk_disable_mtu_disc6(sock *s)
|
|
|
|
{
|
|
|
|
int dont = IPV6_PMTUDISC_DONT;
|
|
|
|
|
|
|
|
if (setsockopt(s->fd, SOL_IPV6, IPV6_MTU_DISCOVER, &dont, sizeof(dont)) < 0)
|
|
|
|
ERR("IPV6_MTU_DISCOVER");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-24 14:37:30 +00:00
|
|
|
|
|
|
|
int sk_priority_control = 7;
|
|
|
|
|
2014-05-18 09:42:26 +00:00
|
|
|
static inline int
|
2013-06-24 14:37:30 +00:00
|
|
|
sk_set_priority(sock *s, int prio)
|
|
|
|
{
|
|
|
|
if (setsockopt(s->fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)) < 0)
|
2014-05-18 09:42:26 +00:00
|
|
|
ERR("SO_PRIORITY");
|
2013-06-24 14:37:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-05-18 09:42:26 +00:00
|
|
|
|
2022-01-08 17:31:56 +00:00
|
|
|
static inline int
|
|
|
|
sk_set_freebind(sock *s)
|
|
|
|
{
|
|
|
|
int y = 1;
|
|
|
|
|
|
|
|
if (sk_is_ipv4(s))
|
|
|
|
if (setsockopt(s->fd, SOL_IP, IP_FREEBIND, &y, sizeof(y)) < 0)
|
|
|
|
ERR("IP_FREEBIND");
|
|
|
|
|
|
|
|
if (sk_is_ipv6(s))
|
|
|
|
if (setsockopt(s->fd, SOL_IPV6, IPV6_FREEBIND, &y, sizeof(y)) < 0)
|
|
|
|
ERR("IPV6_FREEBIND");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|