1. A method of handling data packets in a network device, said method comprising: receiving an incoming data packet; parsing the incoming data packet to obtain a portion of the incoming data packet, the portion including a packet field; comparing said portion with rules stored in a rule table of the network device, wherein each rule of said rules specifies a set of actions and includes at least one rule field, the at least one rule field including a rule field value, a mask, and a selection flag, the mask specifying a mask-specified subset of the rule field value, and wherein the comparing further includes applying the mask to the packet field to obtain a packet field value, and to the rule field value to obtain a mask-specified rule field value, and obtaining a comparison result by comparing the packet field value against the mask-specified rule field value; selecting a match between said portion and a particular rule of said rules, based on the comparison result and the selection flag, including selecting the match for the rule field when either the comparison result is positive and the selection flag is positive, or when the comparison result is negative and the selection flag is negative; and executing a particular set of actions specified by said particular rule.