Hidden AF_INET* inside sysdep/
This commit is contained in:
parent
5b218c3d9b
commit
6ffa8f5393
8 changed files with 34 additions and 26 deletions
|
@ -43,7 +43,7 @@ typedef struct birdsock {
|
|||
uint lifindex; /* local interface that received the datagram */
|
||||
/* laddr and lifindex are valid only if SKF_LADDR_RX flag is set to request it */
|
||||
|
||||
int af; /* Address family (AF_INET, AF_INET6 or 0 for non-IP) of fd */
|
||||
int fam; /* Address family (SK_FAM_* or 0 for non-IP) of fd */
|
||||
int fd; /* System-dependent data */
|
||||
int index; /* Index in poll buffer */
|
||||
int rcv_ttl; /* TTL of last received datagram */
|
||||
|
@ -115,6 +115,12 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shou
|
|||
#define SK_UNIX_PASSIVE 8
|
||||
#define SK_UNIX 9
|
||||
|
||||
/* Socket families */
|
||||
|
||||
#define SK_FAM_NONE 0
|
||||
#define SK_FAM_IPV4 4
|
||||
#define SK_FAM_IPV6 6
|
||||
|
||||
/*
|
||||
* For SK_UDP or SK_IP sockets setting DA/DP allows to use sk_send(),
|
||||
* otherwise sk_send_to() must be used.
|
||||
|
|
|
@ -204,11 +204,11 @@ bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version)
|
|||
|
||||
switch (inet_version) {
|
||||
case 4:
|
||||
sk->af = AF_INET;
|
||||
sk->fam = SK_FAM_IPV4;
|
||||
sk->flags |= SKF_V4ONLY;
|
||||
break;
|
||||
case 6:
|
||||
sk->af = AF_INET6;
|
||||
sk->fam = SK_FAM_IPV6;
|
||||
sk->flags |= SKF_V6ONLY;
|
||||
break;
|
||||
default:
|
||||
|
@ -247,10 +247,10 @@ bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa)
|
|||
sk->flags = SKF_THREAD | SKF_BIND | SKF_HIGH_PORT;
|
||||
|
||||
if (ipa_is_ip4(local)) {
|
||||
sk->af = AF_INET;
|
||||
sk->fam = SK_FAM_IPV4;
|
||||
sk->flags |= SKF_V4ONLY;
|
||||
} else {
|
||||
sk->af = AF_INET6;
|
||||
sk->fam = SK_FAM_IPV6;
|
||||
sk->flags |= SKF_V6ONLY;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ ospf_sk_open(struct ospf_iface *ifa)
|
|||
sk->dport = OSPF_PROTO;
|
||||
sk->saddr = ifa->addr->ip;
|
||||
sk->iface = ifa->iface;
|
||||
sk->af = ospf_is_v2(p) ? AF_INET : AF_INET6;
|
||||
sk->fam = ospf_is_v2(p) ? SK_FAM_IPV4 : SK_FAM_IPV6;
|
||||
|
||||
sk->tos = ifa->cf->tx_tos;
|
||||
sk->priority = ifa->cf->tx_priority;
|
||||
|
@ -194,7 +194,7 @@ ospf_open_vlink_sk(struct ospf_proto *p)
|
|||
sock *sk = sk_new(p->p.pool);
|
||||
sk->type = SK_IP;
|
||||
sk->dport = OSPF_PROTO;
|
||||
sk->af = ospf_is_v2(p) ? AF_INET : AF_INET6;
|
||||
sk->fam = ospf_is_v2(p) ? SK_FAM_IPV4 : SK_FAM_IPV6;
|
||||
|
||||
/* FIXME: configurable tos/priority ? */
|
||||
sk->tos = IP_PREC_INTERNET_CONTROL;
|
||||
|
|
|
@ -412,7 +412,7 @@ radv_sk_open(struct radv_iface *ifa)
|
|||
sk->type = SK_IP;
|
||||
sk->dport = ICMPV6_PROTO;
|
||||
sk->saddr = ifa->addr->ip;
|
||||
sk->af = AF_INET6;
|
||||
sk->fam = SK_FAM_IPV6;
|
||||
|
||||
sk->ttl = 255; /* Mandatory for Neighbor Discovery packets */
|
||||
sk->rx_hook = radv_rx_hook;
|
||||
|
|
|
@ -713,7 +713,7 @@ rip_open_socket(struct rip_iface *ifa)
|
|||
|
||||
sock *sk = sk_new(p->p.pool);
|
||||
sk->type = SK_UDP;
|
||||
sk->af = rip_is_v2(p) ? AF_INET : AF_INET6;
|
||||
sk->fam = rip_is_v2(p) ? SK_FAM_IPV4 : SK_FAM_IPV6;
|
||||
sk->sport = ifa->cf->port;
|
||||
sk->dport = ifa->cf->port;
|
||||
sk->iface = ifa->iface;
|
||||
|
|
|
@ -184,7 +184,7 @@ sk_set_md5_auth(sock *s, ip_addr a, struct iface *ifa, char *passwd)
|
|||
struct tcp_md5sig md5;
|
||||
|
||||
memset(&md5, 0, sizeof(md5));
|
||||
sockaddr_fill((sockaddr *) &md5.tcpm_addr, s->af, a, ifa, 0);
|
||||
sockaddr_fill((sockaddr *) &md5.tcpm_addr, fam_to_af[s->fam], a, ifa, 0);
|
||||
|
||||
if (passwd)
|
||||
{
|
||||
|
|
|
@ -585,6 +585,7 @@ sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
const int fam_to_af[] = { [SK_FAM_IPV4] = AF_INET, [SK_FAM_IPV6] = AF_INET6 };
|
||||
|
||||
/*
|
||||
* IPv6 multicast syscalls
|
||||
|
@ -1184,7 +1185,7 @@ sk_setup(sock *s)
|
|||
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
ERR("O_NONBLOCK");
|
||||
|
||||
if (!s->af)
|
||||
if (!s->fam)
|
||||
return 0;
|
||||
|
||||
if (ipa_nonzero(s->saddr) && !(s->flags & SKF_BIND))
|
||||
|
@ -1286,7 +1287,7 @@ sk_tcp_connected(sock *s)
|
|||
int sa_len = sizeof(sa);
|
||||
|
||||
if ((getsockname(s->fd, &sa.sa, &sa_len) < 0) ||
|
||||
(sockaddr_read(&sa, s->af, &s->saddr, &s->iface, &s->sport) < 0))
|
||||
(sockaddr_read(&sa, fam_to_af[s->fam], &s->saddr, &s->iface, &s->sport) < 0))
|
||||
log(L_WARN "SOCK: Cannot get local IP address for TCP>");
|
||||
|
||||
s->type = SK_TCP;
|
||||
|
@ -1311,7 +1312,7 @@ sk_passive_connected(sock *s, int type)
|
|||
|
||||
sock *t = sk_new(s->pool);
|
||||
t->type = type;
|
||||
t->af = s->af;
|
||||
t->fam = s->fam;
|
||||
t->fd = fd;
|
||||
t->ttl = s->ttl;
|
||||
t->tos = s->tos;
|
||||
|
@ -1321,10 +1322,10 @@ sk_passive_connected(sock *s, int type)
|
|||
if (type == SK_TCP)
|
||||
{
|
||||
if ((getsockname(fd, &loc_sa.sa, &loc_sa_len) < 0) ||
|
||||
(sockaddr_read(&loc_sa, s->af, &t->saddr, &t->iface, &t->sport) < 0))
|
||||
(sockaddr_read(&loc_sa, fam_to_af[s->fam], &t->saddr, &t->iface, &t->sport) < 0))
|
||||
log(L_WARN "SOCK: Cannot get local IP address for TCP<");
|
||||
|
||||
if (sockaddr_read(&rem_sa, s->af, &t->daddr, &t->iface, &t->dport) < 0)
|
||||
if (sockaddr_read(&rem_sa, fam_to_af[s->fam], &t->daddr, &t->iface, &t->dport) < 0)
|
||||
log(L_WARN "SOCK: Cannot get remote IP address for TCP<");
|
||||
}
|
||||
|
||||
|
@ -1383,28 +1384,28 @@ sk_open(sock *s)
|
|||
s->ttx = ""; /* Force s->ttx != s->tpos */
|
||||
/* Fall thru */
|
||||
case SK_TCP_PASSIVE:
|
||||
fd = socket(s->af, SOCK_STREAM, IPPROTO_TCP);
|
||||
fd = socket(fam_to_af[s->fam], SOCK_STREAM, IPPROTO_TCP);
|
||||
bind_port = s->sport;
|
||||
bind_addr = s->saddr;
|
||||
do_bind = bind_port || ipa_nonzero(bind_addr);
|
||||
break;
|
||||
|
||||
case SK_UDP:
|
||||
fd = socket(s->af, SOCK_DGRAM, IPPROTO_UDP);
|
||||
fd = socket(fam_to_af[s->fam], SOCK_DGRAM, IPPROTO_UDP);
|
||||
bind_port = s->sport;
|
||||
bind_addr = (s->flags & SKF_BIND) ? s->saddr : IPA_NONE;
|
||||
do_bind = 1;
|
||||
break;
|
||||
|
||||
case SK_IP:
|
||||
fd = socket(s->af, SOCK_RAW, s->dport);
|
||||
fd = socket(fam_to_af[s->fam], SOCK_RAW, s->dport);
|
||||
bind_port = 0;
|
||||
bind_addr = (s->flags & SKF_BIND) ? s->saddr : IPA_NONE;
|
||||
do_bind = ipa_nonzero(bind_addr);
|
||||
break;
|
||||
|
||||
case SK_MAGIC:
|
||||
s->af = 0;
|
||||
s->fam = SK_FAM_NONE;
|
||||
fd = s->fd;
|
||||
break;
|
||||
|
||||
|
@ -1446,7 +1447,7 @@ sk_open(sock *s)
|
|||
if (sk_set_high_port(s) < 0)
|
||||
log(L_WARN "Socket error: %s%#m", s->err);
|
||||
|
||||
sockaddr_fill(&sa, s->af, bind_addr, s->iface, bind_port);
|
||||
sockaddr_fill(&sa, fam_to_af[s->fam], bind_addr, s->iface, bind_port);
|
||||
if (bind(fd, &sa.sa, SA_LEN(sa)) < 0)
|
||||
ERR2("bind");
|
||||
}
|
||||
|
@ -1458,7 +1459,7 @@ sk_open(sock *s)
|
|||
switch (s->type)
|
||||
{
|
||||
case SK_TCP_ACTIVE:
|
||||
sockaddr_fill(&sa, s->af, s->daddr, s->iface, s->dport);
|
||||
sockaddr_fill(&sa, fam_to_af[s->fam], s->daddr, s->iface, s->dport);
|
||||
if (connect(fd, &sa.sa, SA_LEN(sa)) >= 0)
|
||||
sk_tcp_connected(s);
|
||||
else if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS &&
|
||||
|
@ -1565,7 +1566,7 @@ sk_sendmsg(sock *s)
|
|||
byte cmsg_buf[CMSG_TX_SPACE];
|
||||
sockaddr dst;
|
||||
|
||||
sockaddr_fill(&dst, s->af, s->daddr, s->iface, s->dport);
|
||||
sockaddr_fill(&dst, fam_to_af[s->fam], s->daddr, s->iface, s->dport);
|
||||
|
||||
struct msghdr msg = {
|
||||
.msg_name = &dst.sa,
|
||||
|
@ -1618,7 +1619,7 @@ sk_recvmsg(sock *s)
|
|||
// rv = ipv4_skip_header(pbuf, rv);
|
||||
//endif
|
||||
|
||||
sockaddr_read(&src, s->af, &s->faddr, NULL, &s->fport);
|
||||
sockaddr_read(&src, fam_to_af[s->fam], &s->faddr, NULL, &s->fport);
|
||||
sk_process_cmsgs(s, &msg);
|
||||
|
||||
if (msg.msg_flags & MSG_TRUNC)
|
||||
|
@ -1840,7 +1841,7 @@ sk_write(sock *s)
|
|||
case SK_TCP_ACTIVE:
|
||||
{
|
||||
sockaddr sa;
|
||||
sockaddr_fill(&sa, s->af, s->daddr, s->iface, s->dport);
|
||||
sockaddr_fill(&sa, fam_to_af[s->fam], s->daddr, s->iface, s->dport);
|
||||
|
||||
if (connect(s->fd, &sa.sa, SA_LEN(sa)) >= 0 || errno == EISCONN)
|
||||
sk_tcp_connected(s);
|
||||
|
@ -1861,10 +1862,10 @@ sk_write(sock *s)
|
|||
}
|
||||
|
||||
int sk_is_ipv4(sock *s)
|
||||
{ return s->af == AF_INET; }
|
||||
{ return s->fam == SK_FAM_IPV4; }
|
||||
|
||||
int sk_is_ipv6(sock *s)
|
||||
{ return s->af == AF_INET6; }
|
||||
{ return s->fam == SK_FAM_IPV6; }
|
||||
|
||||
void
|
||||
sk_dump_all(void)
|
||||
|
|
|
@ -102,6 +102,7 @@ int sk_open_unix(struct birdsock *s, char *name);
|
|||
void *tracked_fopen(struct pool *, char *name, char *mode);
|
||||
void test_old_bird(char *path);
|
||||
|
||||
extern const int fam_to_af[];
|
||||
|
||||
/* krt.c bits */
|
||||
|
||||
|
|
Loading…
Reference in a new issue