Previous: Device Status, Up: Device Interface [Contents][Index]
The function device_set_filter makes it possible to filter out
selected data arriving at or leaving the device and forward it to a port.
filter is a list of filter commands, which are applied to incoming
data to determine if the data should be sent to receive_port. The
IPC type of the send right is specified by receive_port_right, it
is either MACH_MSG_TYPE_MAKE_SEND or
MACH_MSG_TYPE_MOVE_SEND. The priority value is used to
order multiple filters.
There can be up to NET_MAX_FILTER commands in filter. The
actual number of commands is passed in filter_count. For the
purpose of the filter test, an internal stack is provided. After all
commands have been processed, the value on the top of the stack
determines if the data is forwarded or the next filter is tried.
The first command is a header which contains two fields: one for flags and the other for the type of interpreter used to run the rest of the commands.
Any combination of the following flags is allowed but at least one of them must be specified.
NETF_INThe filter will be applied to data received by the device.
NETF_OUTThe filter will be applied to data transmitted by the device.
Unless the type is given explicitly the native NETF interpreter will be used. To select an alternative implementation use one of the following types:
NETF_BPFUse Berkeley Packet Filter.
For the listener to know what kind of packet is being received, when the filter code accepts a packet the message sent to receive_port is tagged with either NETF_IN or NETF_OUT.
Each word of the command list specifies a data (push) operation (high order NETF_NBPO bits) as well as a binary operator (low order NETF_NBPA bits). The value to be pushed onto the stack is chosen as follows.
NETF_PUSHLITUse the next short word of the filter as the value.
NETF_PUSHZEROUse 0 as the value.
NETF_PUSHWORD+NUse short word N of the “data” portion of the message as the value.
NETF_PUSHHDR+NUse short word N of the “header” portion of the message as the value.
NETF_PUSHIND+NPops the top long word from the stack and then uses short word N of the “data” portion of the message as the value.
NETF_PUSHHDRIND+NPops the top long word from the stack and then uses short word N of the “header” portion of the message as the value.
NETF_PUSHSTK+NUse long word N of the stack (where the top of stack is long word 0) as the value.
NETF_NOPUSHDon’t push a value.
The unsigned value so chosen is promoted to a long word before being
pushed. Once a value is pushed (except for the case of
NETF_NOPUSH), the top two long words of the stack are popped and
a binary operator applied to them (with the old top of stack as the
second operand). The result of the operator is pushed on the stack.
These operators are:
NETF_NOPDon’t pop off any values and do no operation.
NETF_EQPerform an equal comparison.
NETF_LTPerform a less than comparison.
NETF_LEPerform a less than or equal comparison.
NETF_GTPerform a greater than comparison.
NETF_GEPerform a greater than or equal comparison.
NETF_ANDPerform a bitise boolean AND operation.
NETF_ORPerform a bitise boolean inclusive OR operation.
NETF_XORPerform a bitise boolean exclusive OR operation.
NETF_NEQPerform a not equal comparison.
NETF_LSHPerform a left shift operation.
NETF_RSHPerform a right shift operation.
NETF_ADDPerform an addition.
NETF_SUBPerform a subtraction.
NETF_CORPerform an equal comparison. If the comparison is TRUE, terminate
the filter list. Otherwise, pop the result of the comparison off the
stack.
NETF_CANDPerform an equal comparison. If the comparison is FALSE,
terminate the filter list. Otherwise, pop the result of the comparison
off the stack.
NETF_CNORPerform a not equal comparison. If the comparison is FALSE,
terminate the filter list. Otherwise, pop the result of the comparison
off the stack.
NETF_CNANDPerform a not equal comparison. If the comparison is TRUE,
terminate the filter list. Otherwise, pop the result of the comparison
off the stack. The scan of the filter list terminates when the filter
list is emptied, or a NETF_C... operation terminates the list. At
this time, if the final value of the top of the stack is TRUE,
then the message is accepted for the filter.
The function returns D_SUCCESS if some data was successfully
written, D_INVALID_OPERATION if receive_port is not a valid
send right, and D_NO_SUCH_DEVICE if device does not denote
a device port or the device is dead or not completely open.
Previous: Device Status, Up: Device Interface [Contents][Index]