Explorar el Código

[ipv6] Fix definition of IN6_IS_ADDR_LINKLOCAL()

Fix an erroneous htonl() in the definition of IN6_IS_ADDR_LINKLOCAL(),
and add self-tests for the IN6_IS_ADDR_xxx() family of macros.

Reported-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown hace 10 años
padre
commit
3c7f5f9c4c
Se han modificado 2 ficheros con 39 adiciones y 1 borrados
  1. 1
    1
      src/include/ipxe/in.h
  2. 38
    0
      src/tests/ipv6_test.c

+ 1
- 1
src/include/ipxe/in.h Ver fichero

@@ -61,7 +61,7 @@ struct in6_addr {
61 61
 
62 62
 #define IN6_IS_ADDR_LINKLOCAL( addr )					\
63 63
 	( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==	\
64
-	  htonl ( 0xfe80 ) )
64
+	  htons ( 0xfe80 ) )
65 65
 
66 66
 /**
67 67
  * IPv4 socket address

+ 38
- 0
src/tests/ipv6_test.c Ver fichero

@@ -37,6 +37,30 @@ FILE_LICENCE ( GPL2_OR_LATER );
37 37
 /** Define inline IPv6 address */
38 38
 #define IPV6(...) { __VA_ARGS__ }
39 39
 
40
+/** The unspecified IPv6 address */
41
+static const struct in6_addr sample_unspecified = {
42
+	.s6_addr = IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
44
+};
45
+
46
+/** A sample link-local IPv6 address */
47
+static const struct in6_addr sample_link_local = {
48
+	.s6_addr = IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49
+			  0x00, 0x00, 0x69, 0xff, 0xfe, 0x50, 0x58, 0x45 ),
50
+};
51
+
52
+/** A sample global IPv6 address */
53
+static const struct in6_addr sample_global = {
54
+	.s6_addr = IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
55
+			  0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),
56
+};
57
+
58
+/** A sample multicast IPv6 address */
59
+static const struct in6_addr sample_multicast = {
60
+	.s6_addr = IPV6 ( 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
62
+};
63
+
40 64
 /**
41 65
  * Report an inet6_ntoa() test result
42 66
  *
@@ -97,6 +121,20 @@ FILE_LICENCE ( GPL2_OR_LATER );
97 121
  */
98 122
 static void ipv6_test_exec ( void ) {
99 123
 
124
+	/* Address testing macros */
125
+	ok (   IN6_IS_ADDR_UNSPECIFIED ( &sample_unspecified ) );
126
+	ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_link_local ) );
127
+	ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_global ) );
128
+	ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_multicast ) );
129
+	ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_unspecified ) );
130
+	ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_link_local ) );
131
+	ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_global ) );
132
+	ok (   IN6_IS_ADDR_MULTICAST ( &sample_multicast ) );
133
+	ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_unspecified ) );
134
+	ok (   IN6_IS_ADDR_LINKLOCAL ( &sample_link_local ) );
135
+	ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_global ) );
136
+	ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_multicast ) );
137
+
100 138
 	/* inet6_ntoa() tests */
101 139
 	inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
102 140
 			       0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),

Loading…
Cancelar
Guardar