[Bro-Dev] #754: Complete implementation of switch statement

Bro Tracker bro at tracker.bro-ids.org
Mon Jan 7 09:15:11 PST 2013


#754: Complete implementation of switch statement
----------------------------+------------------------
  Reporter:  seth           |      Owner:  robin
      Type:  Merge Request  |     Status:  closed
  Priority:  Normal         |  Milestone:  Bro2.2
 Component:  Bro            |    Version:  git/master
Resolution:  fixed          |   Keywords:  language
----------------------------+------------------------

Comment (by jsiwek):

 Replying to [comment:18 seth]:
 > There are at least one or two existing "if else" trees I'll be replacing
 with switch statements once this is in master.

 It's already merged.

 Replying to [comment:19 vern]:
 > Okay so can you describe them?  That's all I was asking for originally.

 Here's some existing places I found that might benefit.

 policy/frameworks/control/controller.bro
  - handler for `remote_connection_handshake_done` has a sequence of
 conditional checks to see what command (constant string values) to ask the
 remote Bro to perform

 policy/protocols/http/software.bro
 - there's a sequence of checks for constant string values in the
 `http_header` event for integration with "software" detection

 base/frameworks/cluster/setup-connections.bro
 - setting up the connections between Bro nodes in a cluster setting has a
 lot of logic regarding node type (enums) comparisons that can be tough to
 follow the first time you read it.  Changing some of the "outer layer" of
 the logic to a switch instead might help so that you don't have to read
 down the whole sequence of conditionals to understand the logic.

 base/protocols/http/main.bro
 - another `http_header` handler with several constant string comparisons
 against the header name

 base/protocols/ftp/main.bro
 - a couple places with constant string comparisons to check for a given
 FTP command out of 3-4 specific ones

 base/protocols/conn/main.bro
 - the connection state logic.  There's the outer check for transport
 protocol enum (tcp/udp/icmp), probably not too helpful, but it could be a
 switch.  But for the inner logic of the TCP state, I'm not sure if any of
 that can be reworked to use a switch, but it's brutal to try to reason
 about what's going on the way it is right now (7-8 branches in a
 conditional comparing orig/resp state, which are of constant count value).

 base/protocols/smtp/main.bro
 - SMTP command name and MIME header names are compared to specific sets of
 constant string values

-- 
Ticket URL: <http://tracker.bro-ids.org/bro/ticket/754#comment:20>
Bro Tracker <http://tracker.bro-ids.org/bro>
Bro Issue Tracker



More information about the bro-dev mailing list