|
version 1.1, 2017/08/22 12:33:54
|
version 1.1.1.2, 2021/03/17 19:50:23
|
|
Line 54
|
Line 54
|
| this to gen small latencies */ |
this to gen small latencies */ |
| #define MAX_RX_STEPS 4 |
#define MAX_RX_STEPS 4 |
| |
|
| |
|
| /* |
/* |
| * Tracked Files |
* Tracked Files |
| */ |
*/ |
|
Line 88 static struct resclass rf_class = {
|
Line 89 static struct resclass rf_class = {
|
| NULL |
NULL |
| }; |
}; |
| |
|
| void * | struct rfile * |
| tracked_fopen(pool *p, char *name, char *mode) | rf_open(pool *p, char *name, char *mode) |
| { |
{ |
| FILE *f = fopen(name, mode); |
FILE *f = fopen(name, mode); |
| |
|
| if (f) | if (!f) |
| { | return NULL; |
| struct rfile *r = ralloc(p, &rf_class); | |
| r->f = f; | struct rfile *r = ralloc(p, &rf_class); |
| } | r->f = f; |
| return f; | return r; |
| } |
} |
| |
|
| |
void * |
| |
rf_file(struct rfile *f) |
| |
{ |
| |
return f->f; |
| |
} |
| |
|
| |
int |
| |
rf_fileno(struct rfile *f) |
| |
{ |
| |
return fileno(f->f); |
| |
} |
| |
|
| |
|
| /** |
/** |
| * DOC: Timers |
* DOC: Timers |
| * |
* |
|
Line 478 tm_format_datetime(char *x, struct timeformat *fmt_spe
|
Line 492 tm_format_datetime(char *x, struct timeformat *fmt_spe
|
| strcpy(x, "<too-long>"); |
strcpy(x, "<too-long>"); |
| } |
} |
| |
|
| |
int |
| |
tm_format_real_time(char *x, size_t max, const char *fmt, bird_clock_t t) |
| |
{ |
| |
struct tm tm; |
| |
|
| |
if (!localtime_r(&t, &tm)) |
| |
return 0; |
| |
|
| |
if (!strftime(x, max, fmt, &tm)) |
| |
return 0; |
| |
|
| |
return 1; |
| |
} |
| |
|
| |
|
| /** |
/** |
| * DOC: Sockets |
* DOC: Sockets |
| * |
* |
|
Line 516 static inline void
|
Line 544 static inline void
|
| sockaddr_fill4(struct sockaddr_in *sa, ip_addr a, uint port) |
sockaddr_fill4(struct sockaddr_in *sa, ip_addr a, uint port) |
| { |
{ |
| memset(sa, 0, sizeof(struct sockaddr_in)); |
memset(sa, 0, sizeof(struct sockaddr_in)); |
| #ifdef HAVE_SIN_LEN | #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN |
| sa->sin_len = sizeof(struct sockaddr_in); |
sa->sin_len = sizeof(struct sockaddr_in); |
| #endif |
#endif |
| sa->sin_family = AF_INET; |
sa->sin_family = AF_INET; |
|
Line 1211 sk_setup(sock *s)
|
Line 1239 sk_setup(sock *s)
|
| } |
} |
| #endif |
#endif |
| |
|
| |
if (s->vrf && !s->iface) |
| |
{ |
| |
/* Bind socket to associated VRF interface. |
| |
This is Linux-specific, but so is SO_BINDTODEVICE. */ |
| |
#ifdef SO_BINDTODEVICE |
| |
struct ifreq ifr = {}; |
| |
strcpy(ifr.ifr_name, s->vrf->name); |
| |
if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) |
| |
ERR("SO_BINDTODEVICE"); |
| |
#endif |
| |
} |
| |
|
| if (s->iface) |
if (s->iface) |
| { |
{ |
| #ifdef SO_BINDTODEVICE |
#ifdef SO_BINDTODEVICE |
|
Line 1226 sk_setup(sock *s)
|
Line 1266 sk_setup(sock *s)
|
| #endif |
#endif |
| } |
} |
| |
|
| if (s->priority >= 0) |
|
| if (sk_set_priority(s, s->priority) < 0) |
|
| return -1; |
|
| |
|
| if (sk_is_ipv4(s)) |
if (sk_is_ipv4(s)) |
| { |
{ |
| if (s->flags & SKF_LADDR_RX) |
if (s->flags & SKF_LADDR_RX) |
|
Line 1280 sk_setup(sock *s)
|
Line 1316 sk_setup(sock *s)
|
| return -1; |
return -1; |
| } |
} |
| |
|
| |
/* Must be after sk_set_tos4() as setting ToS on Linux also mangles priority */ |
| |
if (s->priority >= 0) |
| |
if (sk_set_priority(s, s->priority) < 0) |
| |
return -1; |
| |
|
| return 0; |
return 0; |
| } |
} |
| |
|
|
Line 1561 sk_sendmsg(sock *s)
|
Line 1602 sk_sendmsg(sock *s)
|
| struct iovec iov = {s->tbuf, s->tpos - s->tbuf}; |
struct iovec iov = {s->tbuf, s->tpos - s->tbuf}; |
| byte cmsg_buf[CMSG_TX_SPACE]; |
byte cmsg_buf[CMSG_TX_SPACE]; |
| sockaddr dst; |
sockaddr dst; |
| |
int flags = 0; |
| |
|
| sockaddr_fill(&dst, s->af, s->daddr, s->iface, s->dport); |
sockaddr_fill(&dst, s->af, s->daddr, s->iface, s->dport); |
| |
|
|
Line 1571 sk_sendmsg(sock *s)
|
Line 1613 sk_sendmsg(sock *s)
|
| .msg_iovlen = 1 |
.msg_iovlen = 1 |
| }; |
}; |
| |
|
| |
#ifdef CONFIG_DONTROUTE_UNICAST |
| |
/* FreeBSD silently changes TTL to 1 when MSG_DONTROUTE is used, therefore we |
| |
cannot use it for other cases (e.g. when TTL security is used). */ |
| |
if (ipa_is_ip4(s->daddr) && ip4_is_unicast(ipa_to_ip4(s->daddr)) && (s->ttl == 1)) |
| |
flags = MSG_DONTROUTE; |
| |
#endif |
| |
|
| #ifdef CONFIG_USE_HDRINCL |
#ifdef CONFIG_USE_HDRINCL |
| byte hdr[20]; |
byte hdr[20]; |
| struct iovec iov2[2] = { {hdr, 20}, iov }; |
struct iovec iov2[2] = { {hdr, 20}, iov }; |
|
Line 1586 sk_sendmsg(sock *s)
|
Line 1635 sk_sendmsg(sock *s)
|
| if (s->flags & SKF_PKTINFO) |
if (s->flags & SKF_PKTINFO) |
| sk_prepare_cmsgs(s, &msg, cmsg_buf, sizeof(cmsg_buf)); |
sk_prepare_cmsgs(s, &msg, cmsg_buf, sizeof(cmsg_buf)); |
| |
|
| return sendmsg(s->fd, &msg, 0); | return sendmsg(s->fd, &msg, flags); |
| } |
} |
| |
|
| static inline int |
static inline int |