commit - 636933af3b2dcd6470a945faddc984f781a99362
commit + 0908a48d056ce200ce47a2f18ea48314a53422ec
blob - dc46c01d7a49348ac01e72593071b042c21c2e88
blob + 313037de26dee3679d4f939d6491c516725611eb
--- thingsd/parse.y
+++ thingsd/parse.y
static int errors;
-int get_addrs(const char *, struct addresslist *,
- struct portrange *);
+int get_addrs(const char *, struct addresslist *, in_port_t);
static struct thingsd *thingsd;
static struct thing *new_thing;
union {
long long number;
char *string;
- struct portrange port;
+ in_port_t port;
} v;
int lineno;
} YYSTYPE;
yyerror("invalid port: %lld", $1);
YYERROR;
}
- $$.val[0] = htons($1);
- $$.op = 1;
+ $$ = htons($1);
}
| STRING {
int val;
}
free($1);
- $$.val[0] = val;
- $$.op = 1;
+ $$ = val;
}
;
struct thing *thing;
TAILQ_FOREACH(thing, thingsd->things, entry) {
- if (thing->conf.tcp_listen_port.val[0] ==
- $5.val[0]) {
+ if (thing->conf.tcp_listen_port == $5) {
yyerror("tls port already assigned");
YYERROR;
}
}
- new_thing->conf.tcp_listen_port.val[0] = $5.val[0];
- new_thing->conf.tcp_listen_port.op = $5.op;
+ new_thing->conf.tcp_listen_port = $5;
}
| maxclientssub
| PASSWORD STRING {
;
socketopts1 : CONNECT ON PORT port {
- new_thing->conf.tcp_conn_port.val[0] = $4.val[0];
- new_thing->conf.tcp_conn_port.op = $4.op;
+ new_thing->conf.tcp_conn_port = $4;
}
| LISTEN ON opttls PORT port {
struct thing *thing;
TAILQ_FOREACH(thing, thingsd->things, entry) {
- if (thing->conf.tcp_listen_port.val[0] ==
- $5.val[0]) {
+ if (thing->conf.tcp_listen_port == $5) {
yyerror("port already assigned");
YYERROR;
}
}
- new_thing->conf.tcp_listen_port.val[0] = $5.val[0];
- new_thing->conf.tcp_listen_port.op = $5.op;
+ new_thing->conf.tcp_listen_port = $5;
}
| RECEIVE ON PORT port {
struct thing *thing;
TAILQ_FOREACH(thing, thingsd_env->things, entry) {
- if (thing->conf.udp_rcv_port.val[0] == 0 ||
- $4.val[0] == 0)
+ if (thing->conf.udp_rcv_port == 0 || $4 == 0)
continue;
- if (thing->conf.udp_rcv_port.val[0] ==
- $4.val[0]) {
+ if (thing->conf.udp_rcv_port == $4) {
yyerror("UDP thing receive ports must "
"be unique");
YYERROR;
}
}
- new_thing->conf.udp_rcv_port.val[0] = $4.val[0];
- new_thing->conf.udp_rcv_port.op = $4.op;
+ new_thing->conf.udp_rcv_port = $4;
/* if((new_thing->conf.udp_rcv_port = */
/* strdup($4)) == NULL) */
goto done;
/* check that ports match */
- if (sock->conf.port.val[0] != pclient->port.val[0])
+ if (sock->conf.port != pclient->port)
goto done;
/*
free($2);
} '{' optnl thingopts2 '}' {
- if (new_thing->conf.tcp_listen_port.val[0] == 0) {
+ if (new_thing->conf.tcp_listen_port == 0) {
yyerror("thing listen port required");
YYERROR;
}
if (strlen(new_thing->conf.ipaddr) != 0 &&
- new_thing->conf.tcp_conn_port.val[0] == 0) {
+ new_thing->conf.tcp_conn_port == 0) {
yyerror("ipaddr connect port required");
YYERROR;
}
YYERROR;
}
if (strlen(new_thing->conf.udp) != 0 &&
- new_thing->conf.udp_rcv_port.val[0] == 0) {
+ new_thing->conf.udp_rcv_port == 0) {
yyerror("udp receive port required");
YYERROR;
}
if (get_addrs(new_thing->conf.tcp_iface,
new_thing->conf.tcp_al,
- &new_thing->conf.tcp_listen_port) == -1) {
+ new_thing->conf.tcp_listen_port) == -1) {
yyerror("could not get tcp iface addrs");
YYERROR;
}
if (get_addrs(new_thing->conf.udp_iface,
new_thing->conf.udp_al,
- &new_thing->conf.udp_rcv_port) == -1) {
+ new_thing->conf.udp_rcv_port) == -1) {
yyerror("could not get udp iface addrs");
YYERROR;
}
int
host_dns(const char *s, struct addresslist *al, int max,
- struct portrange *port, const char *ifname, int ipproto)
+ in_port_t port, const char *ifname, int ipproto)
{
struct addrinfo hints, *res0, *res;
int error, cnt = 0;
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(__func__);
- if (port != NULL)
- memcpy(&h->port, port, sizeof(h->port));
+ if (port)
+ h->port = port;
if (ifname != NULL) {
if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
sizeof(h->ifname)) {
int
host_if(const char *s, struct addresslist *al, int max,
- struct portrange *port, const char *ifname, int ipproto)
+ in_port_t port, const char *ifname, int ipproto)
{
struct ifaddrs *ifap, *p;
struct sockaddr_in *sain;
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal("calloc");
- if (port != NULL)
- memcpy(&h->port, port, sizeof(h->port));
+ if (port)
+ h->port = port;
if (ifname != NULL) {
if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
sizeof(h->ifname)) {
int
host(const char *s, struct addresslist *al, int max,
- struct portrange *port, const char *ifname, int ipproto)
+ in_port_t port, const char *ifname, int ipproto)
{
struct address *h;
h = host_v6(s);
if (h != NULL) {
- if (port != NULL)
- memcpy(&h->port, port, sizeof(h->port));
+ if (port)
+ h->port = port;
if (ifname != NULL) {
if (strlcpy(h->ifname, ifname, sizeof(h->ifname)) >=
sizeof(h->ifname)) {
}
int
-get_addrs(const char *addr, struct addresslist *al, struct portrange *port)
+get_addrs(const char *addr, struct addresslist *al, in_port_t port)
{
if (strcmp("", addr) == 0) {
if (host("0.0.0.0", al, 1, port, "0.0.0.0", -1) <= 0) {
blob - d2983a4ff8e6cf2de2dffb955e5bc5d2019586b6
blob + 36badfe0b651edfe3804aa06235601cd44ee1411
--- thingsd/sockets.c
+++ thingsd/sockets.c
void *);
int sockets_dispatch_thingsd(int, struct privsep_proc *, struct imsg *);
-int sockets_socket_af(struct sockaddr_storage *, struct portrange);
+int sockets_socket_af(struct sockaddr_storage *, in_port_t);
int sockets_accept_reserve(int, struct sockaddr *, socklen_t *, int,
volatile int *);
int sockets_dispatch_control(int, struct privsep_proc *, struct imsg *);
sizeof(sock->conf.password)) >= sizeof(sock->conf.password))
fatalx("%s: strlcpy", __func__);
- sock->conf.port.val[0] = p_sock->conf.port.val[0];
- sock->conf.port.op = p_sock->conf.port.op;
+ sock->conf.port = p_sock->conf.port;
sock->conf.tls = p_sock->conf.tls;
sock->conf.tls_protocols = p_sock->conf.tls_protocols;
memcpy(&acp->ss, &a->ss, sizeof(acp->ss));
acp->ipproto = a->ipproto;
acp->prefixlen = a->prefixlen;
- acp->port.val[0] = a->port.val[0];
+ acp->port = a->port;
if (strlen(a->ifname) != 0) {
if (strlcpy(acp->ifname, a->ifname,
sizeof(acp->ifname)) >= sizeof(acp->ifname)) {
memcpy(&acp->ss, &a->ss, sizeof(acp->ss));
acp->ipproto = a->ipproto;
acp->prefixlen = a->prefixlen;
- acp->port.val[0] = a->port.val[0];
+ acp->port = a->port;
if (strlen(a->ifname) != 0) {
if (strlcpy(acp->ifname, a->ifname,
sizeof(acp->ifname)) >= sizeof(acp->ifname)) {
sizeof(sock->conf.password)) >= sizeof(sock->conf.password))
fatalx("%s: strlcpy", __func__);
- sock->conf.port.val[0] = thing->conf.tcp_listen_port.val[0];
- sock->conf.port.op = thing->conf.tcp_listen_port.op;
+ sock->conf.port = thing->conf.tcp_listen_port;
sock->conf.tls = thing->conf.tls;
sock->conf.tls_protocols = thing->conf.tls_protocols;
}
int
-sockets_socket_af(struct sockaddr_storage *ss, struct portrange port)
+sockets_socket_af(struct sockaddr_storage *ss, in_port_t port)
{
switch (ss->ss_family) {
case AF_INET:
- ((struct sockaddr_in *)ss)->sin_port = port.val[0];
+ ((struct sockaddr_in *)ss)->sin_port = port;
((struct sockaddr_in *)ss)->sin_len =
sizeof(struct sockaddr_in);
break;
case AF_INET6:
- ((struct sockaddr_in6 *)ss)->sin6_port = port.val[0];
+ ((struct sockaddr_in6 *)ss)->sin6_port = port;
((struct sockaddr_in6 *)ss)->sin6_len =
sizeof(struct sockaddr_in6);
break;
}
int
-sockets_create_socket(struct addresslist *al, struct portrange port, int type)
+sockets_create_socket(struct addresslist *al, in_port_t port, int type)
{
struct addrinfo hints;
struct address *a;
if (bind(fd, (struct sockaddr *)&a->ss, a->ss.ss_len) == -1) {
close(fd);
log_info("%s: can't bind to port %d", __func__,
- ntohs(port.val[0]));
+ ntohs(port));
goto fail;
}
if (type == S_TCP) {
}
int
-sockets_open_client(char *ip_addr, struct portrange *port)
+sockets_open_client(char *ip_addr, in_port_t port)
{
int fd = -1;
}
TAILQ_FOREACH(a, &al, entry) {
- if (sockets_socket_af(&a->ss, *port) == -1) {
+ if (sockets_socket_af(&a->ss, port) == -1) {
log_warnx("%s: sockets_socket_af", __func__);
return (-1);
}
if (client == NULL)
goto err2;
- client->port.val[0] = sock->conf.port.val[0];
- client->port.op = sock->conf.port.op;
+ client->port = sock->conf.port;
memset(&client->timeout, 0, sizeof(struct event));
evtimer_set(&client->timeout, sockets_client_sub_timeout, client);
blob - 3da903d65403f56b25cbac2154f8de10d250dbed
blob + 2e8ffa00c0207ab069f054d2e0969bc8c3131c05
--- thingsd/thingsd.c
+++ thingsd/thingsd.c
if (thing->conf.type == S_TCP) {
if (thing->conf.persist == 1) {
if ((thing->fd = sockets_open_client(thing->conf.ipaddr,
- &thing->conf.tcp_conn_port)) == -1) {
+ thing->conf.tcp_conn_port)) == -1) {
log_warnx("%s: ipaddr connection failed",
__func__);
if (reconn)
case S_DEV:
if (thing->conf.persist == 0) {
if ((thing->fd = sockets_open_client(thing->conf.ipaddr,
- &thing->conf.tcp_conn_port)) == -1) {
+ thing->conf.tcp_conn_port)) == -1) {
log_warnx("%s: temporary ipaddr connection"
" failed", __func__);
return;
break;
case S_UDP:
default:
- log_info("write %d bytes: %s", package->len, package->pkt);
write(thing->fd, package->pkt, package->len);
break;
}
blob - 919489e63b0c04db861748562a90042037166adb
blob + c63f48d8b2595640c015476949de5126e4a531fe
--- thingsd/thingsd.h
+++ thingsd/thingsd.h
};
TAILQ_HEAD(subscriptionlist, subscription);
-struct portrange {
- in_port_t val[2];
- uint8_t op;
-};
-
struct address {
TAILQ_ENTRY(address) entry;
struct sockaddr_storage ss;
int ipproto;
int prefixlen;
- struct portrange port;
+ in_port_t port;
char ifname[IFNAMSIZ];
};
TAILQ_HEAD(addresslist, address);
char name[THINGSD_MAXNAME];
int fd;
- struct portrange port;
+ in_port_t port;
time_t join_time;
size_t subs;
int ipv4;
int ipv6;
- struct portrange port;
+ in_port_t port;
size_t max_clients;
char password[THINGSD_MAXTEXT];
char udp[THINGSD_MAXTEXT];
char udp_iface[THINGSD_MAXTEXT];
- struct portrange tcp_listen_port;
- struct portrange tcp_conn_port;
- struct portrange udp_rcv_port;
+ in_port_t tcp_listen_port;
+ in_port_t tcp_conn_port;
+ in_port_t udp_rcv_port;
int baud;
int data_bits;
*sockets_get_socket(struct thingsd *, int);
struct socket
*sockets_get_socket_byid(struct thingsd *, int);
-int sockets_create_socket(struct addresslist *, struct portrange, int);
-int sockets_open_client(char *, struct portrange *);
+int sockets_create_socket(struct addresslist *, in_port_t, int);
+int sockets_open_client(char *, in_port_t);
int sockets_privinit(struct socket *);
int sockets_client_cmp(struct client *, struct client *);
void sockets_parse_sockets(struct thingsd *);
struct address *host_v4(const char *);
struct address *host_v6(const char *);
int host_dns(const char *, struct addresslist *,
- int, struct portrange *, const char *, int);
+ int, in_port_t, const char *, int);
int host_if(const char *, struct addresslist *,
- int, struct portrange *, const char *, int);
+ int, in_port_t, const char *, int);
int host(const char *, struct addresslist *,
- int, struct portrange *, const char *, int);
+ int, in_port_t, const char *, int);
int is_if_in_group(const char *, const char *);
/* tls.c */