commit 0908a48d056ce200ce47a2f18ea48314a53422ec from: Tracey Emery date: Mon Feb 8 16:32:40 2021 UTC remove portrange, since we are never going to use a range of ports. remove missed log_info line commit - 636933af3b2dcd6470a945faddc984f781a99362 commit + 0908a48d056ce200ce47a2f18ea48314a53422ec blob - dc46c01d7a49348ac01e72593071b042c21c2e88 blob + 313037de26dee3679d4f939d6491c516725611eb --- thingsd/parse.y +++ thingsd/parse.y @@ -94,8 +94,7 @@ void clear_config(struct thingsd *xconf); 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; @@ -112,7 +111,7 @@ typedef struct { union { long long number; char *string; - struct portrange port; + in_port_t port; } v; int lineno; } YYSTYPE; @@ -253,8 +252,7 @@ port : NUMBER { yyerror("invalid port: %lld", $1); YYERROR; } - $$.val[0] = htons($1); - $$.op = 1; + $$ = htons($1); } | STRING { int val; @@ -266,8 +264,7 @@ port : NUMBER { } free($1); - $$.val[0] = val; - $$.op = 1; + $$ = val; } ; @@ -311,15 +308,13 @@ locationopts1 : bindopts2 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 { @@ -426,37 +421,31 @@ opttls : /* empty */ { ; 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) */ @@ -526,7 +515,7 @@ subthings : THING '{' STRING optcomma STRING '}' { goto done; /* check that ports match */ - if (sock->conf.port.val[0] != pclient->port.val[0]) + if (sock->conf.port != pclient->port) goto done; /* @@ -708,12 +697,12 @@ thing : THING STRING { 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; } @@ -728,7 +717,7 @@ thing : THING STRING { 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; } @@ -740,14 +729,14 @@ thing : THING STRING { 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; } @@ -1562,7 +1551,7 @@ host_v6(const char *s) 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; @@ -1593,8 +1582,8 @@ host_dns(const char *s, struct addresslist *al, int ma 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)) { @@ -1635,7 +1624,7 @@ host_dns(const char *s, struct addresslist *al, int ma 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; @@ -1659,8 +1648,8 @@ host_if(const char *s, struct addresslist *al, int max 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)) { @@ -1709,7 +1698,7 @@ host_if(const char *s, struct addresslist *al, int max 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; @@ -1720,8 +1709,8 @@ host(const char *s, struct addresslist *al, int max, 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)) { @@ -1786,7 +1775,7 @@ end: } 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 @@ -51,7 +51,7 @@ void bufferevent_read_pressure_cb(struct evbuffer *, 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 *); @@ -224,8 +224,7 @@ sockets_dup_new_socket(struct socket *p_sock, struct s 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; @@ -247,7 +246,7 @@ sockets_dup_new_socket(struct socket *p_sock, struct s 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)) { @@ -333,7 +332,7 @@ sockets_conf_new_socket(struct thingsd *env, struct th 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)) { @@ -351,8 +350,7 @@ sockets_conf_new_socket(struct thingsd *env, struct th 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; @@ -387,16 +385,16 @@ done: } 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; @@ -408,7 +406,7 @@ sockets_socket_af(struct sockaddr_storage *ss, struct } 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; @@ -454,7 +452,7 @@ sockets_create_socket(struct addresslist *al, struct p 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) { @@ -474,7 +472,7 @@ fail: } int -sockets_open_client(char *ip_addr, struct portrange *port) +sockets_open_client(char *ip_addr, in_port_t port) { int fd = -1; @@ -488,7 +486,7 @@ sockets_open_client(char *ip_addr, struct portrange *p } 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); } @@ -902,8 +900,7 @@ sockets_socket_conn(int fd, short event, void *arg) 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 @@ -786,7 +786,7 @@ thingsd_thing_setup(struct thingsd *env, struct thing 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) @@ -855,7 +855,7 @@ thingsd_write_to_things(struct package *package) 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; @@ -872,7 +872,6 @@ thingsd_write_to_things(struct package *package) 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 @@ -126,17 +126,12 @@ struct subscription { }; 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); @@ -168,7 +163,7 @@ struct client { char name[THINGSD_MAXNAME]; int fd; - struct portrange port; + in_port_t port; time_t join_time; size_t subs; @@ -191,7 +186,7 @@ struct socket_config { int ipv4; int ipv6; - struct portrange port; + in_port_t port; size_t max_clients; char password[THINGSD_MAXTEXT]; @@ -288,9 +283,9 @@ struct thing_config { 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; @@ -415,8 +410,8 @@ struct socket *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 *); @@ -446,11 +441,11 @@ int cmdline_symset(char *); 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 */