@@ -890,7 +890,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
890890int
891891pcap_compile_nopcap (int snaplen_arg , int linktype_arg ,
892892 struct bpf_program * program ,
893- const char * buf , int optimize , bpf_u_int32 mask )
893+ const char * buf , int optimize , bpf_u_int32 mask )
894894{
895895 pcap_t * p ;
896896 int ret ;
@@ -7828,58 +7828,54 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst,
78287828 inst -> b = b ;
78297829 break ;
78307830 case Q_ICMPV6 :
7831- /*
7832- * Do the computation only if the packet contains
7833- * the protocol in question.
7834- */
7835- b = gen_proto_abbrev_internal (cstate , Q_IPV6 );
7836- if (inst -> b ) {
7837- gen_and (inst -> b , b );
7838- }
7839- inst -> b = b ;
7840-
7841- /*
7842- * Check if we have an icmp6 next header
7843- */
7844- b = gen_cmp (cstate , OR_LINKPL , 6 , BPF_B , 58 );
7845- if (inst -> b ) {
7846- gen_and (inst -> b , b );
7847- }
7848- inst -> b = b ;
7849-
7850-
7851- s = gen_abs_offset_varpart (cstate , & cstate -> off_linkpl );
7852- /*
7853- * If "s" is non-null, it has code to arrange that the
7854- * X register contains the variable part of the offset
7855- * of the link-layer payload. Add to it the offset
7856- * computed into the register specified by "index",
7857- * and move that into the X register. Otherwise, just
7858- * load into the X register the offset computed into
7859- * the register specified by "index".
7860- */
7861- if (s != NULL ) {
7862- sappend (s , xfer_to_a (cstate , inst ));
7863- sappend (s , new_stmt (cstate , BPF_ALU |BPF_ADD |BPF_X ));
7864- sappend (s , new_stmt (cstate , BPF_MISC |BPF_TAX ));
7865- } else {
7866- s = xfer_to_x (cstate , inst );
7867- }
7831+ /*
7832+ * Do the computation only if the packet contains
7833+ * the protocol in question.
7834+ */
7835+ b = gen_proto_abbrev_internal (cstate , Q_IPV6 );
7836+ if (inst -> b )
7837+ gen_and (inst -> b , b );
7838+ inst -> b = b ;
78687839
7869- /*
7870- * Load the item at the sum of the offset we've put in the
7871- * X register, the offset of the start of the network
7872- * layer header from the beginning of the link-layer
7873- * payload, and the constant part of the offset of the
7874- * start of the link-layer payload.
7875- */
7876- tmp = new_stmt (cstate , BPF_LD |BPF_IND |size_code );
7877- tmp -> s .k = cstate -> off_linkpl .constant_part + cstate -> off_nl + 40 ;
7840+ /*
7841+ * Check if we have an icmp6 next header
7842+ */
7843+ b = gen_cmp (cstate , OR_LINKPL , 6 , BPF_B , 58 );
7844+ if (inst -> b )
7845+ gen_and (inst -> b , b );
7846+ inst -> b = b ;
7847+
7848+ s = gen_abs_offset_varpart (cstate , & cstate -> off_linkpl );
7849+ /*
7850+ * If "s" is non-null, it has code to arrange that the
7851+ * X register contains the variable part of the offset
7852+ * of the link-layer payload. Add to it the offset
7853+ * computed into the register specified by "index",
7854+ * and move that into the X register. Otherwise, just
7855+ * load into the X register the offset computed into
7856+ * the register specified by "index".
7857+ */
7858+ if (s != NULL ) {
7859+ sappend (s , xfer_to_a (cstate , inst ));
7860+ sappend (s , new_stmt (cstate , BPF_ALU |BPF_ADD |BPF_X ));
7861+ sappend (s , new_stmt (cstate , BPF_MISC |BPF_TAX ));
7862+ } else
7863+ s = xfer_to_x (cstate , inst );
7864+
7865+ /*
7866+ * Load the item at the sum of the offset we've put in the
7867+ * X register, the offset of the start of the network
7868+ * layer header from the beginning of the link-layer
7869+ * payload, and the constant part of the offset of the
7870+ * start of the link-layer payload.
7871+ */
7872+ tmp = new_stmt (cstate , BPF_LD |BPF_IND |size_code );
7873+ tmp -> s .k = cstate -> off_linkpl .constant_part + cstate -> off_nl + 40 ;
78787874
7879- sappend (s , tmp );
7880- sappend (inst -> s , s );
7875+ sappend (s , tmp );
7876+ sappend (inst -> s , s );
78817877
7882- break ;
7878+ break ;
78837879 }
78847880 inst -> regno = regno ;
78857881 s = new_stmt (cstate , BPF_ST );
@@ -8539,7 +8535,7 @@ gen_ifindex(compiler_state_t *cstate, int ifindex)
85398535 /* match packets on this interface */
85408536 b0 = gen_cmp (cstate , OR_LINKHDR , 4 , BPF_W , ifindex );
85418537 break ;
8542- default :
8538+ default :
85438539#if defined(linux )
85448540 /*
85458541 * This is Linux; we require PF_PACKET support.
@@ -9280,7 +9276,7 @@ gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
92809276#endif
92819277 b0 = gen_vlan_no_bpf_extensions (cstate , vlan_num ,
92829278 has_vlan_tag );
9283- break ;
9279+ break ;
92849280
92859281 case DLT_IEEE802_11 :
92869282 case DLT_PRISM_HEADER :
@@ -9295,7 +9291,7 @@ gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
92959291 /*NOTREACHED*/
92969292 }
92979293
9298- cstate -> vlan_stack_depth ++ ;
9294+ cstate -> vlan_stack_depth ++ ;
92999295
93009296 return (b0 );
93019297}
@@ -9321,38 +9317,38 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
93219317 if (setjmp (cstate -> top_ctx ))
93229318 return (NULL );
93239319
9324- if (cstate -> label_stack_depth > 0 ) {
9325- /* just match the bottom-of-stack bit clear */
9326- b0 = gen_mcmp (cstate , OR_PREVMPLSHDR , 2 , BPF_B , 0 , 0x01 );
9327- } else {
9328- /*
9329- * We're not in an MPLS stack yet, so check the link-layer
9330- * type against MPLS.
9331- */
9332- switch (cstate -> linktype ) {
9333-
9334- case DLT_C_HDLC : /* fall through */
9335- case DLT_HDLC :
9336- case DLT_EN10MB :
9337- case DLT_NETANALYZER :
9338- case DLT_NETANALYZER_TRANSPARENT :
9339- b0 = gen_linktype (cstate , ETHERTYPE_MPLS );
9340- break ;
9341-
9342- case DLT_PPP :
9343- b0 = gen_linktype (cstate , PPP_MPLS_UCAST );
9344- break ;
9345-
9346- /* FIXME add other DLT_s ...
9347- * for Frame-Relay/and ATM this may get messy due to SNAP headers
9348- * leave it for now */
9349-
9350- default :
9351- bpf_error (cstate , "no MPLS support for %s" ,
9352- pcap_datalink_val_to_description_or_dlt (cstate -> linktype ));
9353- /*NOTREACHED*/
9354- }
9355- }
9320+ if (cstate -> label_stack_depth > 0 ) {
9321+ /* just match the bottom-of-stack bit clear */
9322+ b0 = gen_mcmp (cstate , OR_PREVMPLSHDR , 2 , BPF_B , 0 , 0x01 );
9323+ } else {
9324+ /*
9325+ * We're not in an MPLS stack yet, so check the link-layer
9326+ * type against MPLS.
9327+ */
9328+ switch (cstate -> linktype ) {
9329+
9330+ case DLT_C_HDLC : /* fall through */
9331+ case DLT_HDLC :
9332+ case DLT_EN10MB :
9333+ case DLT_NETANALYZER :
9334+ case DLT_NETANALYZER_TRANSPARENT :
9335+ b0 = gen_linktype (cstate , ETHERTYPE_MPLS );
9336+ break ;
9337+
9338+ case DLT_PPP :
9339+ b0 = gen_linktype (cstate , PPP_MPLS_UCAST );
9340+ break ;
9341+
9342+ /* FIXME add other DLT_s ...
9343+ * for Frame-Relay/and ATM this may get messy due to SNAP headers
9344+ * leave it for now */
9345+
9346+ default :
9347+ bpf_error (cstate , "no MPLS support for %s" ,
9348+ pcap_datalink_val_to_description_or_dlt (cstate -> linktype ));
9349+ /*NOTREACHED*/
9350+ }
9351+ }
93569352
93579353 /* If a specific MPLS label is requested, check it */
93589354 if (has_label_num ) {
@@ -9367,23 +9363,23 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
93679363 b0 = b1 ;
93689364 }
93699365
9370- /*
9371- * Change the offsets to point to the type and data fields within
9372- * the MPLS packet. Just increment the offsets, so that we
9373- * can support a hierarchy, e.g. "mpls 100000 && mpls 1024" to
9374- * capture packets with an outer label of 100000 and an inner
9375- * label of 1024.
9376- *
9377- * Increment the MPLS stack depth as well; this indicates that
9378- * we're checking MPLS-encapsulated headers, to make sure higher
9379- * level code generators don't try to match against IP-related
9380- * protocols such as Q_ARP, Q_RARP etc.
9381- *
9382- * XXX - this is a bit of a kludge. See comments in gen_vlan().
9383- */
9384- cstate -> off_nl_nosnap += 4 ;
9385- cstate -> off_nl += 4 ;
9386- cstate -> label_stack_depth ++ ;
9366+ /*
9367+ * Change the offsets to point to the type and data fields within
9368+ * the MPLS packet. Just increment the offsets, so that we
9369+ * can support a hierarchy, e.g. "mpls 100000 && mpls 1024" to
9370+ * capture packets with an outer label of 100000 and an inner
9371+ * label of 1024.
9372+ *
9373+ * Increment the MPLS stack depth as well; this indicates that
9374+ * we're checking MPLS-encapsulated headers, to make sure higher
9375+ * level code generators don't try to match against IP-related
9376+ * protocols such as Q_ARP, Q_RARP etc.
9377+ *
9378+ * XXX - this is a bit of a kludge. See comments in gen_vlan().
9379+ */
9380+ cstate -> off_nl_nosnap += 4 ;
9381+ cstate -> off_nl += 4 ;
9382+ cstate -> label_stack_depth ++ ;
93879383 return (b0 );
93889384}
93899385
@@ -10098,8 +10094,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
1009810094 bpf_error (cstate , "'sio' supported only on SS7" );
1009910095 /* sio coded on 1 byte so max value 255 */
1010010096 if (jvalue > 255 )
10101- bpf_error (cstate , "sio value %u too big; max value = 255" ,
10102- jvalue );
10097+ bpf_error (cstate , "sio value %u too big; max value = 255" ,
10098+ jvalue );
1010310099 b0 = gen_ncmp (cstate , OR_PACKET , newoff_sio , BPF_B , 0xffffffffU ,
1010410100 jtype , reverse , jvalue );
1010510101 break ;
@@ -10108,13 +10104,13 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
1010810104 newoff_opc += 3 ;
1010910105
1011010106 /* FALLTHROUGH */
10111- case M_OPC :
10112- if (cstate -> off_opc == OFFSET_NOT_SET )
10107+ case M_OPC :
10108+ if (cstate -> off_opc == OFFSET_NOT_SET )
1011310109 bpf_error (cstate , "'opc' supported only on SS7" );
1011410110 /* opc coded on 14 bits so max value 16383 */
1011510111 if (jvalue > 16383 )
10116- bpf_error (cstate , "opc value %u too big; max value = 16383" ,
10117- jvalue );
10112+ bpf_error (cstate , "opc value %u too big; max value = 16383" ,
10113+ jvalue );
1011810114 /* the following instructions are made to convert jvalue
1011910115 * to the form used to write opc in an ss7 message*/
1012010116 val1 = jvalue & 0x00003c00 ;
@@ -10133,12 +10129,12 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
1013310129 /* FALLTHROUGH */
1013410130
1013510131 case M_DPC :
10136- if (cstate -> off_dpc == OFFSET_NOT_SET )
10132+ if (cstate -> off_dpc == OFFSET_NOT_SET )
1013710133 bpf_error (cstate , "'dpc' supported only on SS7" );
1013810134 /* dpc coded on 14 bits so max value 16383 */
1013910135 if (jvalue > 16383 )
10140- bpf_error (cstate , "dpc value %u too big; max value = 16383" ,
10141- jvalue );
10136+ bpf_error (cstate , "dpc value %u too big; max value = 16383" ,
10137+ jvalue );
1014210138 /* the following instructions are made to convert jvalue
1014310139 * to the forme used to write dpc in an ss7 message*/
1014410140 val1 = jvalue & 0x000000ff ;
@@ -10155,12 +10151,12 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
1015510151 /* FALLTHROUGH */
1015610152
1015710153 case M_SLS :
10158- if (cstate -> off_sls == OFFSET_NOT_SET )
10154+ if (cstate -> off_sls == OFFSET_NOT_SET )
1015910155 bpf_error (cstate , "'sls' supported only on SS7" );
1016010156 /* sls coded on 4 bits so max value 15 */
1016110157 if (jvalue > 15 )
10162- bpf_error (cstate , "sls value %u too big; max value = 15" ,
10163- jvalue );
10158+ bpf_error (cstate , "sls value %u too big; max value = 15" ,
10159+ jvalue );
1016410160 /* the following instruction is made to convert jvalue
1016510161 * to the forme used to write sls in an ss7 message*/
1016610162 jvalue = jvalue << 4 ;
0 commit comments