1 We don't export s6_addr16 and don't have
2 suitable uint16_t member in in6_addr
3 --- snort-2.9.9.0/src/sfutil/sf_ip.h.~2~ 2017-02-01 21:45:38.917735171 +0300
4 +++ snort-2.9.9.0/src/sfutil/sf_ip.h 2017-02-01 21:48:52.021491697 +0300
7 #include "snort_debug.h" /* for inline definition */
11 /* define SFIP_ROBUST to check pointers passed into the sfip libs.
12 * Robustification should not be enabled if the client code is trustworthy.
16 #if !defined(s6_addr8)
17 -#define s6_addr8 __u6_addr.__u6_addr8
19 +#define s6_addr8 _S6_un._S6_u8
21 +#define s6_addr8 u6_addr.u6_addr8
24 #if !defined(s6_addr16)
25 -#define s6_addr16 __u6_addr.__u6_addr16
27 +/* Unfortunately, we don't have uint16_t[] member here */
29 +#define s6_addr16 u6_addr.u6_addr16
32 #if !defined(s6_addr32)
33 -#define s6_addr32 __u6_addr.__u6_addr32
35 +#define s6_addr32 _S6_un._S6_u32
37 +#define s6_addr32 u6_addr.u6_addr32
45 # define ia8 ip.s6_addr
47 # define ia16 ip.s6_addr16
49 # define ia32 ip.s6_addr32
53 * need to determine if it's safe to not check these pointers */\
54 static inline int sfraw_is_set(const struct in6_addr *addr) {
55 /* ARG_CHECK1(ip, -1); */
57 + return (addr->s6_addr32[3] || addr->s6_addr32[0] || addr->s6_addr32[1] || ((uint16_t*)(addr->s6_addr32))[4] ||
58 + (((uint16_t*)(addr->s6_addr32))[5] && ((uint16_t*)(addr->s6_addr32))[5] != 0xFFFF)) ? 1 : 0;
60 return (addr->s6_addr32[3] || addr->s6_addr32[0] || addr->s6_addr32[1] || addr->s6_addr16[4] ||
61 (addr->s6_addr16[5] && addr->s6_addr16[5] != 0xFFFF)) ? 1 : 0;
65 static inline int sfaddr_is_set(const sfaddr_t *addr) {
66 /* ARG_CHECK1(ip, -1); */
67 return ((addr->family == AF_INET && addr->ia32[3]) ||
68 (addr->family == AF_INET6 &&
70 + (addr->ia32[0] || addr->ia32[1] || addr->ia32[3] || ((uint16_t*)(addr->ia32))[4] ||
71 + (((uint16_t *)(addr->ia32))[5] && ((uint16_t*)(addr->ia32))[5] != 0xFFFF)))) ? 1 : 0;
73 (addr->ia32[0] || addr->ia32[1] || addr->ia32[3] || addr->ia16[4] ||
74 (addr->ia16[5] && addr->ia16[5] != 0xFFFF)))) ? 1 : 0;
78 static inline int sfip_is_set(const sfcidr_t *ip) {
80 /* Returns 1 if the IPv6 address appears mapped. 0 otherwise. */
81 static inline int sfip_ismapped(const sfaddr_t *ip) {
85 + return (ip->ia32[0] || ip->ia32[1] || ((uint16_t*)(ip->ia32))[4] || ( ((uint16_t*)(ip->ia32))[5] != 0xffff && ((uint16_t*)(ip->ia32))[5])) ? 0 : 1;
87 return (ip->ia32[0] || ip->ia32[1] || ip->ia16[4] || (ip->ia16[5] != 0xffff && ip->ia16[5])) ? 0 : 1;
91 /* Support function for sfip_compare */
94 /* Check the first 80 bits in an IPv6 address, and */
95 /* verify they're zero. If not, it's not a loopback */
96 - if(ip->ia32[0] || ip->ia32[1] || ip->ia16[4]) return 0;
98 + if(ip->ia32[0] || ip->ia32[1] || ((uint16_t *)(ip->ia32))[4]) return 0;
100 + if ( ((uint16_t *)(ip->ia32))[5] == 0xffff ) {
102 + if(ip->ia32[0] || ip->ia32[1] || ip->ia16[4]) return 0;
104 if ( ip->ia16[5] == 0xffff ) {
106 /* ::ffff: IPv4 mapped over IPv6 */
108 * 10.0.0.0 - 10.255.255.255 (10/8 prefix)
112 /* Check if the 3rd 32-bit int is zero */
114 + if ( !((uint16_t *)(ip->ia32))[5] ) {
116 if ( !ip->ia16[5] ) {
118 /* ::ipv4 compatible ipv6 */
119 /* ::1 is the IPv6 loopback */
120 return ( (ip->ia8[12] == 10)
121 --- snort-2.9.9.0/src/sfutil/sfrt.h.1 2017-02-01 21:50:21.485565677 +0300
122 +++ snort-2.9.9.0/src/sfutil/sfrt.h 2017-02-01 21:51:56.601538134 +0300
125 subtable = ((dir_table_t *)rt)->sub_table;
128 + index = ntohs (((uint16_t*)(ip->ia8))[6]);
130 index = ntohs(ip->ia16[6]);
132 if( !subtable->entries[index] || subtable->lengths[index] )
134 return table->data[subtable->entries[index]];
135 --- snort-2.9.9.0/src/sfutil/sfrt_flat.h.1 2017-02-01 21:53:43.221557566 +0300
136 +++ snort-2.9.9.0/src/sfutil/sfrt_flat.h 2017-02-01 21:55:02.016896936 +0300
138 rt = (dir_table_flat_t *)(&base[table->rt]);
139 subtable = (dir_sub_table_flat_t *)(&base[rt->sub_table]);
142 + index = ntohs(((uint16_t*)(ip->ia8))[6]);
144 index = ntohs(ip->ia16[6]);
146 entries_value = (Entry_Value *)(&base[subtable->entries_value]);
147 entries_length = (Entry_Len *)(&base[subtable->entries_length]);
148 if( !entries_value[index] || entries_length[index] )
149 --- snort-2.9.9.0/src/sfutil/sf_ip.c 2016-06-07 10:47:49.000000000 +0300
150 +++ snort-2.9.9.0/src/sfutil/sf_ip.c 2017-02-01 22:03:00.217171822 +0300
152 new_octet = (chr == '.');
154 addr = (sfaddr_t*)dst;
156 + addr->ia32[0] = addr->ia32[1] = ((uint16_t*)(addr->ia8))[4] = 0;
157 + ((uint16_t*)(addr->ia32))[5] = 0xFFFF;
159 addr->ia32[0] = addr->ia32[1] = addr->ia16[4] = 0;
160 addr->ia16[5] = 0xFFFF;
162 dst = &addr->ia32[3];
167 dst->family = family;
168 if(family == AF_INET) {
170 + dst->ia32[0] = dst->ia32[1] = ((uint16_t*)(dst->ia32))[4] = 0;
171 + ((uint16_t*)(dst->ia32))[5] = 0xFFFF;
173 dst->ia32[0] = dst->ia32[1] = dst->ia16[4] = 0;
174 dst->ia16[5] = 0xFFFF;
176 dst->ia32[3] = *(uint32_t*)src;
177 } else if(family == AF_INET6) {
178 memcpy(sfaddr_get_ip6_ptr(dst), src, 16);
179 @@ -612,16 +622,27 @@
181 /* Check the first 80 bits in an IPv6 address, and */
182 /* verify they're zero. If not, it's not a loopback */
184 + if(ip->ia32[0] || ip->ia32[1] || ((uint16_t*)(ip->ia8))[4])
186 if(ip->ia32[0] || ip->ia32[1] || ip->ia16[4])
191 + if(((uint16_t*)(ip->ia8))[5] == 0xFFFF)
193 if(ip->ia16[5] == 0xFFFF)
196 /* ::ffff:7f00:0/104 is ipv4 compatible ipv6 */
197 return (ip->ia8[12] == 0x7f);
201 + if(!((uint16_t*)(ip->ia8))[5])
206 /* ::7f00:0/104 is ipv4 compatible ipv6 */
207 /* ::1 is the IPv6 loopback */
208 --- snort-2.9.9.0/src/decode.c.1 2017-02-01 22:26:01.531260324 +0300
209 +++ snort-2.9.9.0/src/decode.c 2017-02-01 22:30:34.379039380 +0300
210 @@ -3188,9 +3188,17 @@
212 /* Multicast addresses only specify the first 16 and last 40 bits.
213 Others should be zero. */
215 + if ((((uint16_t*)(ip_dst->s6_addr32))[1] != 0) ||
217 if ((ip_dst->s6_addr16[1] != 0) ||
219 (ip_dst->s6_addr32[1] != 0) ||
221 + (((uint16_t*)(ip_dst->s6_addr32))[4] != 0) ||
223 (ip_dst->s6_addr16[4] != 0) ||
225 (ip_dst->s6_addr[10] != 0))
227 DecoderEvent(p, DECODE_IPV6_DST_RESERVED_MULTICAST,
228 @@ -3201,10 +3209,18 @@
229 if (ip_dst->s6_addr[1] == IP6_MULTICAST_SCOPE_INTERFACE)
233 + if ((((uint16_t*)(ip_dst->s6_addr32))[1] != 0) ||
235 if ((ip_dst->s6_addr16[1] != 0) ||
237 (ip_dst->s6_addr32[1] != 0) ||
238 (ip_dst->s6_addr32[2] != 0) ||
240 + (((uint16_t*)(ip_dst->s6_addr32))[6] != 0))
242 (ip_dst->s6_addr16[6] != 0))
246 DecoderEvent(p, DECODE_IPV6_DST_RESERVED_MULTICAST,