nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/perl
2  
3 my $debug = 0;
4 # 0: off
5 # 1: specific debug
6 # 2: full debug
7  
8 #
9 # verify that display filter names correspond with the PROTABBREV of
10 # of the dissector. Enforces the dissector to have a source
11 # filename of format packet-PROTABBREV.c
12 #
13 # Usage: checkfiltername.pl <file or files>
14  
15 #
16 # Copyright 2011 Michael Mann (see AUTHORS file)
17 #
18 # Wireshark - Network traffic analyzer
19 # By Gerald Combs <gerald@wireshark.org>
20 # Copyright 1998 Gerald Combs
21 #
22 # This program is free software; you can redistribute it and/or
23 # modify it under the terms of the GNU General Public License
24 # as published by the Free Software Foundation; either version 2
25 # of the License, or (at your option) any later version.
26 #
27 # This program is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
31 #
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the Free Software
34 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35  
36 #
37 # Example:
38 # ~/work/wireshark/trunk/epan/dissectors> ../../tools/checkfiltername.pl packet-3com-xns.c
39 # packet-3com-xns.c (2 (of 2) fields)
40 # 102 3comxns.type doesn't match PROTOABBREV of 3com-xns
41 # 106 3comxns.type doesn't match PROTOABBREV of 3com-xns
42 #
43 # or checkfiltername.pl packet-*.c, which will check all the dissector files.
44 #
45 #
46  
47 use warnings;
48 use strict;
49 use Getopt::Long;
50  
51 my @elements;
52 my @elements_dup;
53 my @protocols;
54 my %filters;
55 my %expert_filters;
56 my @acceptedprefixes = ("dcerpc-");
57 my @asn1automatedfilelist;
58 my @dcerpcautomatedfilelist;
59 my @idl2wrsautomatedfilelist;
60 my @filemanipulationfilelist;
61 my @prefixfilelist;
62 my @nofieldfilelist;
63 my %unique;
64 my @uniquefilelist;
65 my @noregprotocolfilelist;
66 my @periodinfilternamefilelist;
67  
68 my $showlinenoFlag = '';
69 my $showautomatedFlag = '';
70  
71 my $state = "";
72 # "s_unknown",
73 # "s_start",
74 # "s_in_hf_register_info",
75 # "s_hf_register_info_entry",
76 # "s_header_field_info_entry",
77 # "s_header_field_info_entry_start",
78 # "s_header_field_info_entry_name",
79 # "s_header_field_info_entry_abbrev",
80 # "s_header_field_info_entry_abbrev_end",
81 # "s_start_expert",
82 # "s_in_ei_register_info",
83 # "s_ei_register_info_entry",
84 # "s_ei_register_info_entry_start",
85 # "s_ei_register_info_entry_abbrev_end",
86 # "s_nofields"
87  
88 my $restofline;
89 my $filecount = 0;
90 my $currfile = "";
91 my $protabbrev = "";
92 my $protabbrev_index;
93 my $PFNAME_value = "";
94 my $linenumber = 1;
95 my $totalerrorcount = 0;
96 my $errorfilecount = 0;
97 my $onefield = 0;
98 my $nofields = 0;
99 my $noperiod = 0;
100 my $noregprotocol = 1;
101 my $automated = 0;
102 my $more_tokens;
103 my $showall = 0;
104  
105 my $comment = 0;
106  
107 sub checkprotoabbrev {
108 my $abbrev = "";
109 my $abbrevpos;
110 my $proto_abbrevpos1;
111 my $proto_abbrevpos2;
112 my $afterabbrev = "";
113 my $check_dup_abbrev = "";
114 my $modprotabbrev = "";
115 my $errorline = 0;
116 my $prefix;
117  
118 if (($automated == 0) || ($showall == 1)) {
119 $abbrevpos = index($_[0], ".");
120 if ($abbrevpos == -1) {
121 $abbrev = $_[0];
122 }
123 else {
124 $abbrev = substr($_[0], 0, $abbrevpos);
125 $afterabbrev = substr($_[0], $abbrevpos+1, length($_[0])-$abbrevpos);
126 $check_dup_abbrev = $afterabbrev;
127 $afterabbrev = substr($afterabbrev, 0, length($abbrev));
128 }
129  
130 if ($abbrev ne $protabbrev) {
131 $errorline = 1;
132  
133 #check if there is a supported protocol that matches the abbrev.
134 #This may be a case of filename != PROTOABBREV
135 foreach (@protocols) {
136 if ($abbrev eq $_) {
137 $errorline = 0;
138 } elsif (index($_, ".") != -1) {
139  
140 #compare from start of string for each period found
141 $proto_abbrevpos1 = 0;
142 while ((($proto_abbrevpos2 = index($_, ".", $proto_abbrevpos1)) != -1) &&
143 ($errorline == 1)) {
144 if ($abbrev eq substr($_, 0, $proto_abbrevpos2)) {
145 $errorline = 0;
146 }
147  
148 $proto_abbrevpos1 = $proto_abbrevpos2+1;
149 }
150 }
151 }
152 }
153  
154 # find any underscores that preface or follow a period
155 if (((index($_[0], "._") >= 0) || (index($_[0], "_.") >= 0)) &&
156 #ASN.1 dissectors can intentionally generating this field name, so don't fault the dissector
157 (index($_[0], "_untag_item_element") < 0)) {
158 if ($showlinenoFlag) {
159 push(@elements, "$_[1] $_[0] contains an unnecessary \'_\'\n");
160 } else {
161 push(@elements, "$_[0] contains an unnecessary \'_\'\n");
162 }
163 }
164  
165 if (($errorline == 1) && ($showall == 0)) {
166 #try some "accepted" variations of PROTOABBREV
167  
168 #replace '-' with '_'
169 $modprotabbrev = $protabbrev;
170 $modprotabbrev =~ s/-/_/g;
171 if ($abbrev eq $modprotabbrev) {
172 $errorline = 0;
173 }
174  
175 #remove '-'
176 if ($errorline == 1) {
177 $modprotabbrev = $protabbrev;
178 $modprotabbrev =~ s/-//g;
179 if ($abbrev eq $modprotabbrev) {
180 $errorline = 0;
181 }
182 }
183  
184 #remove '_'
185 if ($errorline == 1) {
186 $modprotabbrev = $protabbrev;
187 $modprotabbrev =~ s/_//g;
188 if ($abbrev eq $modprotabbrev) {
189 $errorline = 0;
190 }
191 }
192  
193 if ($errorline == 1) {
194 #remove any "accepted" prefix to see if there is still a problem
195 foreach (@acceptedprefixes) {
196 if ($protabbrev =~ /^$_/) {
197 $modprotabbrev = substr($protabbrev, length($_));
198 if ($abbrev eq $modprotabbrev) {
199 push(@prefixfilelist, "$currfile\n");
200 $errorline = 0;
201 }
202 }
203 }
204 }
205 else {
206 push(@filemanipulationfilelist, "$currfile\n");
207 }
208  
209 #now check the acceptable "fields from a different protocol"
210 if ($errorline == 1) {
211 if (is_from_other_protocol_whitelist($_[0], $currfile) == 1) {
212 $errorline = 0;
213 }
214 }
215  
216 #now check the acceptable "fields that include a version number"
217 if ($errorline == 1) {
218 if (is_protocol_version_whitelist($_[0], $currfile) == 1) {
219 $errorline = 0;
220 }
221 }
222 }
223  
224 if ($errorline == 1) {
225 $debug>1 && print "$_[1] $_[0] doesn't match PROTOABBREV of $protabbrev\n";
226 if ($showlinenoFlag) {
227 push(@elements, "$_[1] $_[0] doesn't match PROTOABBREV of $protabbrev\n");
228 } else {
229 push(@elements, "$_[0] doesn't match PROTOABBREV of $protabbrev\n");
230 }
231 }
232  
233 if (($abbrev ne "") && (lc($abbrev) eq lc($afterabbrev))) {
234 #Allow ASN.1 generated files to duplicate part of proto name
235 if ((!(grep {$currfile eq $_ } @asn1automatedfilelist)) &&
236 #Check "approved" whitelist
237 (is_proto_dup_whitelist($abbrev, $check_dup_abbrev) == 0)) {
238 if ($showlinenoFlag) {
239 push(@elements_dup, "$_[1] $_[0] duplicates PROTOABBREV of $abbrev\n");
240 } else {
241 push(@elements_dup, "$_[0] duplicates PROTOABBREV of $abbrev\n");
242 }
243 }
244 }
245 }
246 }
247  
248 sub printprevfile {
249 my $totalfields = keys(%filters);
250 my $count_ele;
251 my $count_dup;
252 my $total_count;
253  
254 foreach (sort keys %filters) {
255 checkprotoabbrev ($filters{$_}, $_);
256 }
257  
258 foreach (sort keys %expert_filters) {
259 checkprotoabbrev ($expert_filters{$_}, $_);
260 }
261  
262 $count_ele = @elements;
263 $count_dup = @elements_dup;
264 $total_count = $count_ele+$count_dup;
265  
266 if ($noregprotocol == 1) {
267 #if no protocol is registered, only worry about duplicates
268 if ($currfile ne "") {
269 push(@noregprotocolfilelist, "$currfile\n");
270 }
271  
272 if ($count_dup > 0) {
273 $errorfilecount++;
274 $totalerrorcount += $count_dup;
275 }
276  
277 if (($showall == 1) || ($count_dup > 0)) {
278 print "\n\n$currfile - NO PROTOCOL REGISTERED\n";
279 if ($showall == 1) {
280 #everything is included, so count all errors
281 $totalerrorcount += $count_ele;
282 if (($count_ele > 0) && ($count_dup == 0)) {
283 $errorfilecount++;
284 }
285  
286 foreach (@elements) {
287 print $_;
288 }
289 }
290 foreach (@elements_dup) {
291 print $_;
292 }
293 }
294 } else {
295 if ($total_count > 0) {
296 $errorfilecount++;
297 $totalerrorcount += $total_count;
298 }
299  
300 if (($automated == 0) || ($showall == 1)) {
301 if ($total_count > 0) {
302 if ($automated == 1) {
303 if ($showall == 1) {
304 print "\n\n$currfile - AUTOMATED ($total_count (of $totalfields) fields)\n";
305 }
306 } else {
307 print "\n\n$currfile ($total_count (of $totalfields) fields)\n";
308 }
309  
310 foreach (@elements) {
311 print $_;
312 }
313 foreach (@elements_dup) {
314 print $_;
315 }
316 }
317  
318 if ((($nofields) || ($totalfields == 0)) && ($currfile ne "")) {
319 if ($showall == 1) {
320 print "\n\n$currfile - NO FIELDS\n";
321 }
322 push(@nofieldfilelist, "$currfile\n");
323 }
324 }
325 }
326 }
327  
328 #--------------------------------------------------------------------
329 # This is a list of dissectors that intentionally have filter names
330 # where the second segment duplicates (at least partially) the name
331 # of the first. The most common case is in ASN.1 dissectors, but
332 # those can be dealt with by looking at the first few lines of the
333 # dissector. This list has been vetted and justification will need
334 # to be provided to add to it. Acknowledge these dissectors aren't
335 # a problem for the pre-commit script
336 #--------------------------------------------------------------------
337 sub is_proto_dup_whitelist {
338 if (($_[0] eq "amf") && (index($_[1], "amf0") >= 0)) {return 1;}
339 if (($_[0] eq "amf") && (index($_[1], "amf3") >= 0)) {return 1;}
340 if (($_[0] eq "amqp") && (index($_[1], "amqp") >= 0)) {return 1;}
341 if (($_[0] eq "bat") && (index($_[1], "batman") >= 0)) {return 1;}
342 if (($_[0] eq "browser") && (index($_[1], "browser_") >= 0)) {return 1;}
343 if (($_[0] eq "dlsw") && (index($_[1], "dlsw_version") >= 0)) {return 1;}
344 if (($_[0] eq "dns") && (index($_[1], "dnskey") >= 0)) {return 1;}
345 if (($_[0] eq "ecmp") && (index($_[1], "ecmp_") >= 0)) {return 1;}
346 if (($_[0] eq "exported_pdu") && (index($_[1], "exported_pdu") >= 0)) {return 1;}
347 if (($_[0] eq "fc") && (index($_[1], "fctl") >= 0)) {return 1;}
348 if (($_[0] eq "fcs") && (index($_[1], "fcsmask") >= 0)) {return 1;}
349 if (($_[0] eq "fmp") && (index($_[1], "fmp") >= 0)) {return 1;}
350 if (($_[0] eq "fr") && (index($_[1], "frame_relay") >= 0)) {return 1;}
351 if (($_[0] eq "mac") && (index($_[1], "macd") >= 0)) {return 1;}
352 if (($_[0] eq "mac") && (index($_[1], "macis") >= 0)) {return 1;}
353 if (($_[0] eq "mih") && (index($_[1], "mihf") >= 0)) {return 1;}
354 if (($_[0] eq "mih") && (index($_[1], "mihcap") >= 0)) {return 1;}
355 if (($_[0] eq "ncp") && (index($_[1], "ncp") >= 0)) {return 1;}
356 if (($_[0] eq "nfs") && (index($_[1], "nfs") >= 0)) {return 1;}
357 if (($_[0] eq "oxid") && (index($_[1], "oxid") >= 0)) {return 1;}
358 if (($_[0] eq "rquota") && (index($_[1], "rquota") >= 0)) {return 1;}
359 if (($_[0] eq "sm") && (index($_[1], "sm_") >= 0)) {return 1;}
360 if (($_[0] eq "smpp") && (index($_[1], "smppplus") >= 0)) {return 1;}
361 if (($_[0] eq "spray") && (index($_[1], "sprayarr") >= 0)) {return 1;}
362 if (($_[0] eq "tds") && (index($_[1], "tds_") >= 0)) {return 1;}
363 if (($_[0] eq "time") && (index($_[1], "time") >= 0)) {return 1;}
364 if (($_[0] eq "tn3270") && (index($_[1], "tn3270e") >= 0)) {return 1;}
365 if (($_[0] eq "usb") && (index($_[1], "usb") >= 0)) {return 1;}
366 if (($_[0] eq "xml") && (index($_[1], "xml") >= 0)) {return 1;}
367  
368 return 0;
369 }
370  
371 #--------------------------------------------------------------------
372 # This is a list of dissectors that intentionally have filter names
373 # shared with other dissectors. This list has been vetted and
374 # justification will need to be provided to add to it.
375 # Acknowledge these dissectors aren't a problem for the pre-commit script
376 #--------------------------------------------------------------------
377 sub is_from_other_protocol_whitelist {
378 my $proto_filename;
379 my $dir_index = rindex($_[1], "\\");
380  
381 #handle directory names on all platforms
382 if ($dir_index < 0) {
383 $dir_index = rindex($_[1], "/");
384 }
385  
386 if ($dir_index < 0) {
387 $proto_filename = $_[1];
388 }
389 else {
390 $proto_filename = substr($_[1], $dir_index+1);
391 }
392  
393 # XXX - may be faster to hash this (note 1-many relationship)?
394 if (($proto_filename eq "packet-bpdu.c") && (index($_[0], "mstp") >= 0)) {return 1;}
395 if (($proto_filename eq "packet-bssap.c") && (index($_[0], "bsap") >= 0)) {return 1;}
396 if (($proto_filename eq "packet-cimetrics.c") && (index($_[0], "llc") >= 0)) {return 1;}
397 if (($proto_filename eq "packet-cipsafety.c") && (index($_[0], "cip") >= 0)) {return 1;}
398 if (($proto_filename eq "packet-cipsafety.c") && (index($_[0], "enip") >= 0)) {return 1;}
399 if (($proto_filename eq "packet-dcerpc-netlogon.c") && (index($_[0], "ntlmssp") >= 0)) {return 1;}
400 if (($proto_filename eq "packet-dcom-oxid.c") && (index($_[0], "dcom") >= 0)) {return 1;}
401 if (($proto_filename eq "packet-dvb-data-mpe.c") && (index($_[0], "mpeg_sect") >= 0)) {return 1;}
402 if (($proto_filename eq "packet-dvb-ipdc.c") && (index($_[0], "ipdc") >= 0)) {return 1;}
403 if (($proto_filename eq "packet-enip.c") && (index($_[0], "cip") >= 0)) {return 1;}
404 if (($proto_filename eq "packet-extreme.c") && (index($_[0], "llc") >= 0)) {return 1;}
405 if (($proto_filename eq "packet-fmp_notify.c") && (index($_[0], "fmp") >= 0)) {return 1;}
406 if (($proto_filename eq "packet-foundry.c") && (index($_[0], "llc") >= 0)) {return 1;}
407 if (($proto_filename eq "packet-glusterfs.c") && (index($_[0], "gluster") >= 0)) {return 1;}
408 if (($proto_filename eq "packet-h248_annex_e.c") && (index($_[0], "h248") >= 0)) {return 1;}
409 if (($proto_filename eq "packet-h248_q1950.c") && (index($_[0], "h248") >= 0)) {return 1;}
410 if (($proto_filename eq "packet-ieee80211.c") && (index($_[0], "eapol") >= 0)) {return 1;}
411 if (($proto_filename eq "packet-ieee80211-radio.c") && (index($_[0], "wlan") >= 0)) {return 1;}
412 if (($proto_filename eq "packet-ieee80211-wlancap.c") && (index($_[0], "wlan") >= 0)) {return 1;}
413 if (($proto_filename eq "packet-ieee802154.c") && (index($_[0], "wpan") >= 0)) {return 1;}
414 if (($proto_filename eq "packet-isup.c") && (index($_[0], "ansi_isup") >= 0)) {return 1;}
415 if (($proto_filename eq "packet-isup.c") && (index($_[0], "bat_ase") >= 0)) {return 1;}
416 if (($proto_filename eq "packet-isup.c") && (index($_[0], "nsap") >= 0)) {return 1;}
417 if (($proto_filename eq "packet-isup.c") && (index($_[0], "x213") >= 0)) {return 1;}
418 if (($proto_filename eq "packet-iwarp-ddp-rdmap.c") && (index($_[0], "iwarp_ddp") >= 0)) {return 1;}
419 if (($proto_filename eq "packet-iwarp-ddp-rdmap.c") && (index($_[0], "iwarp_rdma") >= 0)) {return 1;}
420 if (($proto_filename eq "packet-k12.c") && (index($_[0], "aal2") >= 0)) {return 1;}
421 if (($proto_filename eq "packet-k12.c") && (index($_[0], "atm") >= 0)) {return 1;}
422 if (($proto_filename eq "packet-m3ua.c") && (index($_[0], "mtp3") >= 0)) {return 1;}
423 if (($proto_filename eq "packet-mpeg-dsmcc.c") && (index($_[0], "mpeg_sect") >= 0)) {return 1;}
424 if (($proto_filename eq "packet-mpeg-dsmcc.c") && (index($_[0], "etv.dsmcc") >= 0)) {return 1;}
425 if (($proto_filename eq "packet-mpeg1.c") && (index($_[0], "rtp.payload_mpeg_") >= 0)) {return 1;}
426 if (($proto_filename eq "packet-ndps.c") && (index($_[0], "spx.ndps_") >= 0)) {return 1;}
427 if (($proto_filename eq "packet-pw-atm.c") && (index($_[0], "atm") >= 0)) {return 1;}
428 if (($proto_filename eq "packet-pw-atm.c") && (index($_[0], "pw") >= 0)) {return 1;}
429 if (($proto_filename eq "packet-scsi.c") && (index($_[0], "scsi_sbc") >= 0)) {return 1;}
430 if (($proto_filename eq "packet-sndcp-xid.c") && (index($_[0], "llcgprs") >= 0)) {return 1;}
431 if (($proto_filename eq "packet-wlccp.c") && (index($_[0], "llc") >= 0)) {return 1;}
432 if (($proto_filename eq "packet-wps.c") && (index($_[0], "eap") >= 0)) {return 1;}
433 if (($proto_filename eq "packet-wsp.c") && (index($_[0], "wap") >= 0)) {return 1;}
434 if (($proto_filename eq "packet-xot.c") && (index($_[0], "x25") >= 0)) {return 1;}
435 if (($proto_filename eq "packet-zbee-zcl-misc.c") && (index($_[0], "zbee_zcl_hvac") >= 0)) {return 1;}
436 if (($proto_filename eq "packet-zbee-zcl-misc.c") && (index($_[0], "zbee_zcl_ias") >= 0)) {return 1;}
437  
438 #Understand why, but I think it could be prefixed with "dissector"
439 #prefix (which isn't necessarily "protocol")
440 if (($proto_filename eq "packet-rtcp.c") && (index($_[0], "srtcp") >= 0)) {return 1;}
441 if (($proto_filename eq "packet-rtp.c") && (index($_[0], "srtp") >= 0)) {return 1;}
442 if (($proto_filename eq "packet-dcom-cba-acco.c") && (index($_[0], "cba") >= 0)) {return 1;}
443 if (($proto_filename eq "packet-dcom-cba.c") && (index($_[0], "cba") >= 0)) {return 1;}
444  
445 #XXX - HACK to get around nested "s in field name
446 if (($proto_filename eq "packet-gsm_sim.c") && (index($_[0], "e\\") >= 0)) {return 1;}
447  
448 return 0;
449 }
450  
451 #--------------------------------------------------------------------
452 # This is a list of dissectors that use their (protocol) version number
453 # as part of the first display filter segment, which checkfiltername
454 # usually complains about. Whitelist them so it can pass
455 # pre-commit script
456 #--------------------------------------------------------------------
457 sub is_protocol_version_whitelist {
458 my $proto_filename;
459 my $dir_index = rindex($_[1], "\\");
460  
461 #handle directory names on all platforms
462 if ($dir_index < 0) {
463 $dir_index = rindex($_[1], "/");
464 }
465  
466 if ($dir_index < 0) {
467 $proto_filename = $_[1];
468 }
469 else {
470 $proto_filename = substr($_[1], $dir_index+1);
471 }
472  
473 # XXX - may be faster to hash this?
474 if (($proto_filename eq "packet-ehs.c") && (index($_[0], "ehs2") >= 0)) {return 1;}
475 if (($proto_filename eq "packet-hsrp.c") && (index($_[0], "hsrp2") >= 0)) {return 1;}
476 if (($proto_filename eq "packet-ipv6.c") && (index($_[0], "ip") >= 0)) {return 1;}
477 if (($proto_filename eq "packet-openflow_v1.c") && (index($_[0], "openflow") >= 0)) {return 1;}
478 if (($proto_filename eq "packet-rtnet.c") && (index($_[0], "tdma-v1") >= 0)) {return 1;}
479 if (($proto_filename eq "packet-scsi-osd.c") && (index($_[0], "scsi_osd2") >= 0)) {return 1;}
480 if (($proto_filename eq "packet-sflow.c") && (index($_[0], "sflow_5") >= 0)) {return 1;}
481 if (($proto_filename eq "packet-sflow.c") && (index($_[0], "sflow_245") >= 0)) {return 1;}
482 if (($proto_filename eq "packet-tipc.c") && (index($_[0], "tipcv2") >= 0)) {return 1;}
483  
484  
485 return 0;
486 }
487  
488 # ---------------------------------------------------------------------
489 #
490 # MAIN
491 #
492 GetOptions(
493 'showlineno' => \$showlinenoFlag,
494 'showautomated' => \$showautomatedFlag,
495 );
496  
497 while (<>) {
498 if ($currfile !~ /$ARGV/) {
499 &printprevfile();
500  
501 # New file - reset array and state
502 $filecount++;
503 $currfile = $ARGV;
504  
505 #determine PROTABBREV for dissector based on file name format of (dirs)/packet-PROTABBREV.c or (dirs)/file-PROTABBREV.c
506 $protabbrev_index = rindex($currfile, "packet-");
507 if ($protabbrev_index == -1) {
508 $protabbrev_index = rindex($currfile, "file-");
509 if ($protabbrev_index == -1) {
510 #ignore "non-dissector" files
511 next;
512 }
513  
514 $protabbrev = substr($currfile, $protabbrev_index+length("file-"));
515 $protabbrev_index = rindex($protabbrev, ".");
516 if ($protabbrev_index == -1) {
517 print "$currfile doesn't fit format of file-PROTABBREV.c\n";
518 next;
519 }
520 } else {
521 $protabbrev = substr($currfile, $protabbrev_index+length("packet-"));
522 $protabbrev_index = rindex($protabbrev, ".");
523 if ($protabbrev_index == -1) {
524 print "$currfile doesn't fit format of packet-PROTABBREV.c\n";
525 next;
526 }
527 }
528 $protabbrev = substr($protabbrev, 0, $protabbrev_index);
529  
530 $PFNAME_value = "";
531 $noregprotocol = 1;
532 $automated = 0;
533 $nofields = 0;
534 $onefield = 0;
535 $noperiod = 0;
536 $linenumber = 1;
537 %filters = ( );
538 %expert_filters = ( );
539 @protocols = ( );
540 @elements = ( );
541 @elements_dup = ( );
542 $state = "s_unknown";
543 }
544  
545 if (($automated == 0) && ($showautomatedFlag eq "")) {
546 #DCERPC automated files
547 if ($_ =~ "DO NOT EDIT") {
548 push(@dcerpcautomatedfilelist, "$currfile\n");
549 $automated = 1;
550 next;
551 }
552 #ASN.1 automated files
553 elsif ($_ =~ "Generated automatically by the ASN.1 to Wireshark dissector compiler") {
554 push(@asn1automatedfilelist, "$currfile\n");
555 $automated = 1;
556 next;
557 }
558 #idl2wrs automated files
559 elsif ($_ =~ "Autogenerated from idl2wrs") {
560 push(@idl2wrsautomatedfilelist, "$currfile\n");
561 $automated = 1;
562 next;
563 }
564 }
565  
566 # opening then closing comment
567 if (/(.*?)\/\*.*\*\/(.*)/) {
568 $comment = 0;
569 $_ = "$1$2";
570 # closing then opening comment
571 } elsif (/.*?\*\/(.*?)\/\*/) {
572 $comment = 1;
573 $_ = "$1";
574 # opening comment
575 } elsif (/(.*?)\/\*/) {
576 $comment = 1;
577 $_ = "$1";
578 # closing comment
579 } elsif (/\*\/(.*?)/) {
580 $comment = 0;
581 $_ = "$1";
582 } elsif ($comment == 1) {
583 $linenumber++;
584 next;
585 }
586 # unhandled: more than one complete comment per line
587  
588 chomp;
589  
590 #proto_register_protocol state machine
591 $restofline = $_;
592 $more_tokens = 1;
593  
594 #PFNAME is a popular #define for the proto filter name, so use it for testing
595 if ($restofline =~ /#define\s*PFNAME\s*\"([^\"]*)\"/) {
596 $PFNAME_value = $1;
597 $debug>1 && print "PFNAME: '$1'\n";
598 }
599  
600 until ($more_tokens == 0) {
601 if ($restofline =~ /proto_register_protocol\s*\((.*)/) {
602 $noregprotocol = 0;
603 $restofline = $1;
604 $state = "s_proto_start";
605 } elsif (($state eq "s_proto_start") && ($restofline =~ /^(\s*\"([^\"]*)\"\s*,)\s*(.*)/)) {
606 $restofline = $3;
607 $state = "s_proto_long_name";
608 $debug>1 && print "proto long name: '$2'\n";
609 } elsif (($state eq "s_proto_start") && ($restofline =~ /^(\s*(([\w\d])+)\s*,)\s*(.*)/)) {
610 $restofline = $4;
611 $state = "s_proto_long_name";
612 $debug>1 && print "proto long name: '$2'\n";
613 } elsif (($state eq "s_proto_long_name") && ($restofline =~ /^(\s*\"([^\"]*)\"\s*,)\s*(.*)/)) {
614 $restofline = $3;
615 $state = "s_proto_short_name";
616 $debug>1 && print "proto short name: '$2'\n";
617 } elsif (($state eq "s_proto_long_name") && ($restofline =~ /^(\s*(([\w\d])+)\s*,)\s*(.*)/)) {
618 $restofline = $4;
619 $state = "s_proto_short_name";
620 $debug>1 && print "proto short name: '$2'\n";
621 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*PFNAME\s*(.*)/)) {
622 $more_tokens = 0;
623 $state = "s_proto_filter_name";
624 if ((index($PFNAME_value, ".") != -1) && ($noperiod == 0)) {
625 push(@periodinfilternamefilelist, "$currfile\n");
626 $noperiod = 1;
627 }
628 push(@protocols, $PFNAME_value);
629 $debug>1 && print "proto filter name: '$PFNAME_value'\n";
630 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*\"([^\"]*)\"\s*(.*)/)) {
631 $more_tokens = 0;
632 $state = "s_proto_filter_name";
633 if ((index($1, ".") != -1) && ($noperiod == 0)) {
634 push(@periodinfilternamefilelist, "$currfile\n");
635 $noperiod = 1;
636 }
637 push(@protocols, $1);
638 $debug>1 && print "proto filter name: '$1'\n";
639 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*(([\w\d])+)\s*(.*)/)) {
640 $more_tokens = 0;
641 $state = "s_proto_filter_name";
642 $debug>1 && print "proto filter name: '$1'\n";
643 } else {
644 $more_tokens = 0;
645 }
646 }
647  
648 #retrieving display filters state machine
649 $restofline = $_;
650 $more_tokens = 1;
651 until ($more_tokens == 0) {
652 if ($restofline =~ /\s*static\s*hf_register_info\s*(\w+)\[\](.*)/) {
653 $restofline = $2;
654 $state = "s_start";
655 $debug>1 && print "$linenumber $state\n";
656 } elsif ($restofline =~ /\s*static\s*ei_register_info\s*(\w+)\[\](.*)/) {
657 $restofline = $2;
658 $state = "s_start_expert";
659 $debug>1 && print "$linenumber $state\n";
660 } elsif (($state eq "s_start") && ($restofline =~ /\W+{(.*)/)) {
661 $restofline = $1;
662 $state = "s_in_hf_register_info";
663 $debug>1 && print "$linenumber $state\n";
664 } elsif (($state eq "s_in_hf_register_info") && ($restofline =~ /\W+{(.*)/)) {
665 $restofline = $1;
666 $state = "s_hf_register_info_entry";
667 $debug>1 && print "$linenumber $state\n";
668 $onefield = 1;
669 } elsif (($state eq "s_in_hf_register_info") && ($restofline =~ /\s*};(.*)/)) {
670 $restofline = $1;
671 if ($onefield == 0) {
672 $debug && print "$linenumber NO FIELDS!!!\n";
673 $nofields = 1;
674 $state = "s_nofields";
675 $more_tokens = 0;
676 } else {
677 $state = "s_unknown";
678 }
679 } elsif (($state eq "s_hf_register_info_entry") && ($restofline =~ /\s*&\s*(hf_\w*(\[w*\])?)\s*,?(.*)/)) {
680 $restofline = $3;
681 $debug>1 && print "$linenumber hf_register_info_entry: $1\n";
682 $state = "s_header_field_info_entry";
683 } elsif (($state eq "s_header_field_info_entry") && ($restofline =~ /\s*{(.*)/)) {
684 $restofline = $1;
685 $state = "s_header_field_info_entry_start";
686 $debug>1 && print "$linenumber $state\n";
687 } elsif (($state eq "s_header_field_info_entry_start") && ($restofline =~ /((\"([^\"]*)\")|(\w+))\s*,(.*)/)) {
688 $restofline = $5;
689 $debug>1 && print "$linenumber header_field_info_entry_name: $1\n";
690 $state = "s_header_field_info_entry_name";
691 } elsif (($state eq "s_header_field_info_entry_name") && ($restofline =~ /\"([^\"]*)\"\s*,?(.*)/)) {
692 $restofline = $2;
693 $debug>1 && print "$linenumber header_field_info_entry_abbrev: $1\n";
694 $state = "s_header_field_info_entry_abbrev";
695 $filters{$linenumber} = $1;
696 } elsif (($state eq "s_header_field_info_entry_abbrev") && ($restofline =~ /[^}]*}(.*)/)) {
697 $restofline = $1;
698 $state = "s_header_field_info_entry_abbrev_end";
699 $debug>1 && print "$linenumber $state\n";
700 } elsif (($state eq "s_header_field_info_entry_abbrev_end") && ($restofline =~ /[^}]*}(.*)/)) {
701 $restofline = $1;
702 $state = "s_in_hf_register_info";
703 $debug>1 && print "$linenumber $state\n";
704 } elsif (($state eq "s_start_expert") && ($restofline =~ /\W+{(.*)/)) {
705 $restofline = $1;
706 $state = "s_in_ei_register_info";
707 $debug>1 && print "$linenumber $state\n";
708 } elsif (($state eq "s_in_ei_register_info") && ($restofline =~ /\W+{(.*)/)) {
709 $restofline = $1;
710 $state = "s_ei_register_info_entry";
711 $debug>1 && print "$linenumber $state\n";
712 } elsif (($state eq "s_in_ei_register_info") && ($restofline =~ /\s*};(.*)/)) {
713 $restofline = $1;
714 $state = "s_unknown";
715 } elsif (($state eq "s_ei_register_info_entry") && ($restofline =~ /\s*{(.*)/)) {
716 $restofline = $1;
717 $state = "s_ei_register_info_entry_start";
718 $debug>1 && print "$linenumber $state\n";
719 } elsif (($state eq "s_ei_register_info_entry_start") && ($restofline =~ /\"([^\"]*)\"\s*,(.*)/)) {
720 $restofline = $2;
721 $debug>1 && print "$linenumber ei_register_info_entry_abbrev: $1\n";
722 $expert_filters{$linenumber} = $1;
723 $state = "s_ei_register_info_entry_abbrev_end";
724 } elsif (($state eq "s_ei_register_info_entry_abbrev_end") && ($restofline =~ /[^}]*}(.*)/)) {
725 $restofline = $1;
726 $state = "s_in_ei_register_info";
727 $debug>1 && print "$linenumber $state\n";
728 } else {
729 $more_tokens = 0;
730 }
731 }
732  
733 $linenumber++;
734 }
735  
736 &printprevfile();
737  
738 if ($totalerrorcount > 0) {
739 print "\n\nTOTAL ERRORS: $totalerrorcount";
740  
741 if ($filecount > 1) {
742 print " ($errorfilecount files)\n";
743  
744 print "NO FIELDS: " . scalar(@nofieldfilelist) . "\n";
745 print "AUTOMATED: " . (scalar(@asn1automatedfilelist) + scalar(@dcerpcautomatedfilelist) + scalar(@idl2wrsautomatedfilelist)) . "\n";
746 print "NO PROTOCOL: " . scalar(@noregprotocolfilelist) . "\n";
747  
748 print "\nASN.1 AUTOMATED FILE LIST\n";
749 foreach (@asn1automatedfilelist) {
750 print $_;
751 }
752 print "\nDCE/RPC AUTOMATED FILE LIST\n";
753 foreach (@dcerpcautomatedfilelist) {
754 print $_;
755 }
756 print "\nIDL2WRS AUTOMATED FILE LIST\n";
757 foreach (@idl2wrsautomatedfilelist) {
758 print $_;
759 }
760 print "\n\"FILE MANIPULATION\" FILE LIST\n";
761 @uniquefilelist = grep{ not $unique{$_}++} @filemanipulationfilelist;
762 foreach (@uniquefilelist) {
763 print $_;
764 }
765 print "\nREMOVE PREFIX FILE LIST\n";
766 @uniquefilelist = grep{ not $unique{$_}++} @prefixfilelist;
767 foreach (@uniquefilelist) {
768 print $_;
769 }
770 print "\nNO PROTOCOL REGISTERED FILE LIST\n";
771 foreach (@noregprotocolfilelist) {
772 print $_;
773 }
774 print "\nNO FIELDS FILE LIST\n";
775 foreach (@nofieldfilelist) {
776 print $_;
777 }
778  
779 print "\nPERIOD IN PROTO FILTER NAME FILE LIST\n";
780 foreach (@periodinfilternamefilelist) {
781 print $_;
782 }
783 } else {
784 print "\n";
785 }
786  
787 exit(1); # exit 1 if ERROR
788 }
789  
790 __END__