ref: 15ff38e818d27d48fa8dd9450b0d4cb06b94b67d
parent: 070a9ef753990bc37696f059c1751d25831b5c17
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Dec 17 12:17:26 EST 2017
wifi: use protocol constants from ip/ip.h and ip/ipv6.h for dmatproxy()
--- a/sys/src/9/pc/mkfile
+++ b/sys/src/9/pc/mkfile
@@ -125,7 +125,8 @@
etheriwl.$O: wifi.h
etherwpi.$O: wifi.h
etherrt2860.$O: wifi.h
-wifi.$O: wifi.h etherif.h ../port/netif.h ../ip/ip.h /sys/include/libsec.h
+wifi.$O: wifi.h etherif.h ../port/netif.h /sys/include/libsec.h
+wifi.$O: ../ip/ip.h ../ip/ipv6.h
init.h:D: ../port/initcode.c init9.c
$CC ../port/initcode.c
--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -7,7 +7,6 @@
#include "ureg.h"
#include "../port/error.h"
#include "../port/netif.h"
-#include "../ip/ip.h"
#include "etherif.h"
#include "wifi.h"
@@ -1708,6 +1707,9 @@
* for downstream translation. The proxy does not appear in the
* table.
*/
+#include "../ip/ip.h"
+#include "../ip/ipv6.h"
+
static void
dmatproxy(Block *bp, int upstream, uchar proxy[Eaddrlen], DMAT *t)
{
@@ -1737,30 +1739,30 @@
switch(pkt->type[0]<<8 | pkt->type[1]){
default:
return;
- case 0x0800: /* IPv4 */
- case 0x86dd: /* IPv6 */
+ case ETIP4:
+ case ETIP6:
switch(a[0]&0xF0){
default:
return;
- case 0x40: /* IPv4 */
- if(a+20 > end)
+ case IP_VER4:
+ if(a+IP4HDR > end || (a[0]&15) < IP_HLEN4)
return;
v4tov6(ip, a+12+4*(upstream==0));
proto = a[9];
a += (a[0]&15)*4;
break;
- case 0x60: /* IPv6 */
- if(a+40 > end)
+ case IP_VER6:
+ if(a+IP6HDR > end)
return;
memmove(ip, a+8+16*(upstream==0), 16);
proto = a[6];
- a += 40;
+ a += IP6HDR;
break;
}
if(!upstream)
break;
switch(proto){
- case 58: /* ICMPv6 */
+ case ICMPv6:
if(a+8 > end)
return;
switch(a[0]){
@@ -1784,8 +1786,8 @@
csum = (a[2]<<8 | a[3])^0xFFFF;
while(o+8 <= end && o[1] != 0){
switch(o[0]){
- case 1: /* SLLA, for RS, RA and NS */
- case 2: /* TLLA, for NA and RD */
+ case SRC_LLADDR:
+ case TARGET_LLADDR:
for(i=0; i<Eaddrlen; i += 2)
csum += (o[2+i]<<8 | o[3+i])^0xFFFF;
memmove(mac, o+2, Eaddrlen);
@@ -1802,7 +1804,7 @@
a[2] = csum>>8;
a[3] = csum;
break;
- case 17: /* UDP (bootp) */
+ case UDP: /* for BOOTP */
if(a+42 > end
|| (a[0]<<8 | a[1]) != 68
|| (a[2]<<8 | a[3]) != 67
@@ -1830,7 +1832,7 @@
return;
}
break;
- case 0x0806: /* ARP */
+ case ETARP:
if(a+26 > end || memcmp(a, arp4, sizeof(arp4)) != 0 || (a[7] != 1 && a[7] != 2))
return;
v4tov6(ip, a+14+10*(upstream==0));
--- a/sys/src/9/pc64/mkfile
+++ b/sys/src/9/pc64/mkfile
@@ -125,7 +125,8 @@
etheriwl.$O: wifi.h
etherwpi.$O: wifi.h
etherrt2860.$O: wifi.h
-wifi.$O: wifi.h etherif.h ../port/netif.h ../ip/ip.h /sys/include/libsec.h
+wifi.$O: wifi.h etherif.h ../port/netif.h /sys/include/libsec.h
+wifi.$O: ../ip/ip.h ../ip/ipv6.h
init.h:D: ../port/initcode.c ../pc/init9.c
$CC ../port/initcode.c