@@ -4324,18 +4324,11 @@ struct pkt {
43244324
43254325static void mg_tcpip_call(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
43264326#if MG_ENABLE_PROFILE
4327- const char *names[] = {
4328- "TCPIP_EV_ST_CHG",
4329- "TCPIP_EV_DHCP_DNS",
4330- "TCPIP_EV_DHCP_SNTP",
4331- "TCPIP_EV_ARP",
4332- "TCPIP_EV_TIMER_1S",
4333- "TCPIP_EV_WIFI_SCAN_RESULT",
4334- "TCPIP_EV_WIFI_SCAN_END",
4335- "TCPIP_EV_WIFI_CONNECT_ERR",
4336- "TCPIP_EV_DRIVER",
4337- "TCPIP_EV_USER"
4338- };
4327+ const char *names[] = {"TCPIP_EV_ST_CHG", "TCPIP_EV_DHCP_DNS",
4328+ "TCPIP_EV_DHCP_SNTP", "TCPIP_EV_ARP",
4329+ "TCPIP_EV_TIMER_1S", "TCPIP_EV_WIFI_SCAN_RESULT",
4330+ "TCPIP_EV_WIFI_SCAN_END", "TCPIP_EV_WIFI_CONNECT_ERR",
4331+ "TCPIP_EV_DRIVER", "TCPIP_EV_USER"};
43394332 if (ev != MG_TCPIP_EV_POLL && ev < (int) (sizeof(names) / sizeof(names[0]))) {
43404333 MG_PROF_ADD(c, names[ev]);
43414334 }
@@ -5126,13 +5119,13 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
51265119 if (pkt->pay.len < sizeof(*pkt->ip)) return; // Truncated
51275120 if ((pkt->ip->ver >> 4) != 4) return; // Not IP
51285121 ihl = pkt->ip->ver & 0x0F;
5129- if (ihl < 5) return; // bad IHL
5130- if (pkt->pay.len < (uint16_t)(ihl * 4)) return; // Truncated / malformed
5122+ if (ihl < 5) return; // bad IHL
5123+ if (pkt->pay.len < (uint16_t) (ihl * 4)) return; // Truncated / malformed
51315124 // There can be link padding, take length from IP header
5132- len = mg_ntohs(pkt->ip->len); // IP datagram length
5133- if (len < (ihl * 4) || len > pkt->pay.len) return; // malformed
5134- pkt->pay.len = len; // strip padding
5135- mkpay(pkt, (uint32_t *) pkt->ip + ihl); // account for opts
5125+ len = mg_ntohs(pkt->ip->len); // IP datagram length
5126+ if (len < (ihl * 4) || len > pkt->pay.len) return; // malformed
5127+ pkt->pay.len = len; // strip padding
5128+ mkpay(pkt, (uint32_t *) pkt->ip + ihl); // account for opts
51365129 frag = mg_ntohs(pkt->ip->frag);
51375130 if (frag & IP_MORE_FRAGS_MSK || frag & IP_FRAG_OFFSET_MSK) {
51385131 struct mg_connection *c;
@@ -5147,11 +5140,11 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
51475140 rx_icmp(ifp, pkt);
51485141 } else if (pkt->ip->proto == 17) {
51495142 pkt->udp = (struct udp *) (pkt->pay.buf);
5150- if (pkt->pay.len < sizeof(*pkt->udp)) return; // truncated
5143+ if (pkt->pay.len < sizeof(*pkt->udp)) return; // truncated
51515144 // Take length from UDP header
5152- len = mg_ntohs(pkt->udp->len); // UDP datagram length
5153- if (len < sizeof(*pkt->udp) || len > pkt->pay.len) return; // malformed
5154- pkt->pay.len = len; // strip excess data
5145+ len = mg_ntohs(pkt->udp->len); // UDP datagram length
5146+ if (len < sizeof(*pkt->udp) || len > pkt->pay.len) return; // malformed
5147+ pkt->pay.len = len; // strip excess data
51555148 mkpay(pkt, pkt->udp + 1);
51565149 MG_VERBOSE(("UDP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
51575150 mg_ntohs(pkt->udp->sport), mg_print_ip4, &pkt->ip->dst,
@@ -5172,7 +5165,7 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
51725165 pkt->tcp = (struct tcp *) (pkt->pay.buf);
51735166 if (pkt->pay.len < sizeof(*pkt->tcp)) return;
51745167 off = pkt->tcp->off >> 4; // account for opts
5175- if (pkt->pay.len < (uint16_t)(4 * off)) return;
5168+ if (pkt->pay.len < (uint16_t) (4 * off)) return;
51765169 mkpay(pkt, (uint32_t *) pkt->tcp + off);
51775170 MG_VERBOSE(("TCP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
51785171 mg_ntohs(pkt->tcp->sport), mg_print_ip4, &pkt->ip->dst,
@@ -5201,7 +5194,7 @@ static void rx_ip6(struct mg_tcpip_if *ifp, struct pkt *pkt) {
52015194 case 51: // Authentication RFC-4302
52025195 MG_INFO(("IPv6 extension header %d", (int) next));
52035196 next = nhdr[0];
5204- len += (uint16_t)(8 * (nhdr[1] + 1));
5197+ len += (uint16_t) (8 * (nhdr[1] + 1));
52055198 nhdr += 8 * (nhdr[1] + 1);
52065199 break;
52075200 case 44: // Fragment 4.5
@@ -5271,8 +5264,8 @@ static void mg_tcpip_rx(struct mg_tcpip_if *ifp, void *buf, size_t len) {
52715264 struct pkt pkt;
52725265 memset(&pkt, 0, sizeof(pkt));
52735266 pkt.pay.buf = pkt.raw.buf = (char *) buf;
5274- pkt.pay.len = pkt.raw.len = len; // payload = raw
5275- pkt.eth = (struct eth *) buf; // Ethernet = raw
5267+ pkt.pay.len = pkt.raw.len = len; // payload = raw
5268+ pkt.eth = (struct eth *) buf; // Ethernet = raw
52765269 if (pkt.raw.len < sizeof(*pkt.eth)) return; // Truncated - runt?
52775270 if (ifp->enable_mac_check &&
52785271 memcmp(pkt.eth->dst, ifp->mac, sizeof(pkt.eth->dst)) != 0 &&
@@ -5288,7 +5281,7 @@ static void mg_tcpip_rx(struct mg_tcpip_if *ifp, void *buf, size_t len) {
52885281 mkpay(&pkt, pkt.eth + 1);
52895282 if (pkt.eth->type == mg_htons(0x806)) {
52905283 pkt.arp = (struct arp *) (pkt.pay.buf);
5291- if (pkt.pay.len < sizeof(*pkt.arp)) return; // Truncated
5284+ if (pkt.pay.len < sizeof(*pkt.arp)) return; // Truncated
52925285 mg_tcpip_call(ifp, MG_TCPIP_EV_ARP, &pkt.raw);
52935286 rx_arp(ifp, &pkt);
52945287 } else if (pkt.eth->type == mg_htons(0x86dd)) {
@@ -5556,7 +5549,7 @@ static void init_closure(struct mg_connection *c) {
55565549 struct connstate *s = (struct connstate *) (c + 1);
55575550 if (c->is_udp == false && c->is_listening == false &&
55585551 c->is_connecting == false) { // For TCP conns,
5559- uint32_t rem_ip = c->rem.ip4;
5552+ uint32_t rem_ip = c->rem.ip4;
55605553 tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
55615554 c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
55625555 settmout(c, MIP_TTYPE_FIN);
@@ -5623,7 +5616,8 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
56235616 len);
56245617 } else {
56255618 res = mg_iobuf_add(&c->send, c->send.len, buf, len);
5626- // res == 0 means an OOM condition (iobuf couldn't resize), yet this is so far recoverable, let the caller decide
5619+ // res == 0 means an OOM condition (iobuf couldn't resize), yet this is so
5620+ // far recoverable, let the caller decide
56275621 }
56285622 return res;
56295623}
0 commit comments