@@ -4592,16 +4592,13 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
45924592 /* this order is important */
45934593 memcpy (a , addr , sizeof (a ));
45944594 memcpy (m , mask , sizeof (m ));
4595- b1 = NULL ;
4595+ b1 = gen_true ( cstate ) ;
45964596 for (int i = 3 ; i >= 0 ; i -- ) {
4597- // Same as the Q_IP case in gen_host().
4598- if (m [i ] == 0 && a [i ] == 0 )
4599- continue ;
46004597 b0 = gen_mcmp (cstate , OR_LINKPL , offset + 4 * i , BPF_W ,
46014598 ntohl (a [i ]), ntohl (m [i ]));
4602- b1 = b1 ? gen_and (b0 , b1 ) : b0 ;
4599+ b1 = gen_and (b0 , b1 );
46034600 }
4604- return b1 ? b1 : gen_true ( cstate ) ;
4601+ return b1 ;
46054602}
46064603
46074604/*
@@ -5153,31 +5150,16 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
51535150
51545151 case Q_IP :
51555152 b0 = gen_linktype (cstate , ETHERTYPE_IP );
5156- /*
5157- * Belt and braces: if other code works correctly, any host
5158- * bits are clear and mask == 0 means addr == 0. In this case
5159- * the call to gen_hostop() would produce an "always true"
5160- * instruction block and ANDing it with the link type check
5161- * would be a no-op.
5162- */
5163- if (mask == 0 && addr == 0 )
5164- return b0 ;
51655153 b1 = gen_hostop (cstate , addr , mask , dir , 12 , 16 );
51665154 return gen_and (b0 , b1 );
51675155
51685156 case Q_RARP :
51695157 b0 = gen_linktype (cstate , ETHERTYPE_REVARP );
5170- // Same as for Q_IP above.
5171- if (mask == 0 && addr == 0 )
5172- return b0 ;
51735158 b1 = gen_hostop (cstate , addr , mask , dir , 14 , 24 );
51745159 return gen_and (b0 , b1 );
51755160
51765161 case Q_ARP :
51775162 b0 = gen_linktype (cstate , ETHERTYPE_ARP );
5178- // Same as for Q_IP above.
5179- if (mask == 0 && addr == 0 )
5180- return b0 ;
51815163 b1 = gen_hostop (cstate , addr , mask , dir , 14 , 24 );
51825164 return gen_and (b0 , b1 );
51835165
@@ -5202,12 +5184,6 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
52025184 case Q_DEFAULT :
52035185 case Q_IPV6 :
52045186 b0 = gen_linktype (cstate , ETHERTYPE_IPV6 );
5205- // Same as the Q_IP case in gen_host().
5206- if (
5207- ! memcmp (mask , & in6addr_any , sizeof (struct in6_addr )) &&
5208- ! memcmp (addr , & in6addr_any , sizeof (struct in6_addr ))
5209- )
5210- return b0 ;
52115187 b1 = gen_hostop6 (cstate , addr , mask , dir , 8 , 24 );
52125188 return gen_and (b0 , b1 );
52135189 }
0 commit comments