JNodeOS v1.2.0 API

edu.utah.janos.nodeos
Class DemultiplexKey

java.lang.Object
  |
  +--edu.utah.janos.nodeos.pj_DemultiplexKey
        |
        +--edu.utah.janos.nodeos.DemultiplexKey
Direct Known Subclasses:
SimpleDemultiplexKey

public class DemultiplexKey
extends edu.utah.janos.nodeos.pj_DemultiplexKey

A key for matching incoming packets.

Author:
Janos Ministry of Development
See Also:
InChannel, CutThroughChannel

Inner classes inherited from class edu.utah.janos.nodeos.pj_DemultiplexKey
pj_DemultiplexKey.ByteMask
 
Field Summary
static int ETH_ALLFLAGS
           
static int ETH_ANYDADDR
           
static int ETH_ANYETYPE
           
static int ETH_ANYSADDR
           
static int IPV4_ALLFLAGS
           
static int IPV4_ANYDADDR
           
static int IPV4_ANYPROTO
           
static int IPV4_ANYSADDR
           
 
Constructor Summary
DemultiplexKey(Flow flow)
          Create a new demultiplex key.
 
Method Summary
 void add(int offset, byte b)
          Add a segment matching the given byte offset bytes from the last segment.
 void add(int offset, int length, byte[] sequence, byte[] mask)
          Add a segment that matches the given sequence of bytes, skipping offset bytes from the previous segment.
 void add(int offset, short s)
          Add a segment matching the given short offset bytes from the last segment.
 void addANEP(int offset, byte version, boolean allVersions, short protocolID)
          Add a segment that matches an ANEP header.
 void addETH(int offset, int flags, byte[] src, byte[] dst, short type)
          Add a segment to match an Ethernet header.
 void addIPv4(int offset, int flags, int source, int srcMask, int dest, int dstMask, byte protocol)
          Add a segment to match an IPv4 header.
 void addTCP(int offset, int srcPort, int destPort)
          Add a segment to match a TCP header, needs to be preceded by a call to matchIPv4.
 void addUDP(int offset, int srcPort, int destPort)
          Add a segment to match a UDP header, needs to be preceded by a call to matchIPv4.
 int length()
          Get the "length" of this key.
 void match(int offset, int i)
          Add a segment matching the given int offset bytes from the last segment.
 void match(int offset, long l)
          Add a segment matching the given long offset bytes from the last segment.
 int matches(byte[] payload, int payloadStart, int payloadLength)
          Test a packet to see if this key would match that packet.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ETH_ANYSADDR

public static final int ETH_ANYSADDR

ETH_ANYDADDR

public static final int ETH_ANYDADDR

ETH_ANYETYPE

public static final int ETH_ANYETYPE

ETH_ALLFLAGS

public static final int ETH_ALLFLAGS

IPV4_ANYSADDR

public static final int IPV4_ANYSADDR

IPV4_ANYDADDR

public static final int IPV4_ANYDADDR

IPV4_ANYPROTO

public static final int IPV4_ANYPROTO

IPV4_ALLFLAGS

public static final int IPV4_ALLFLAGS
Constructor Detail

DemultiplexKey

public DemultiplexKey(Flow flow)
Create a new demultiplex key. By default, the key is empty (and thus it matches everything).
Method Detail

add

public void add(int offset,
                int length,
                byte[] sequence,
                byte[] mask)
Add a segment that matches the given sequence of bytes, skipping offset bytes from the previous segment. The mask says which bytes of sequence are relevant. If mask is null, all bytes are relevant.

XXX currently mask must be null.

XXX should throw a custom exception for bogon parameters (vs. Error).

Parameters:
offset - The offset from the end of the previous segment.
length - The length of the bytes to match
sequence - The sequence of bytes to match
mask - If non-null, its a bit mask that indicates which bytes in `sequence' should be matched.

add

public void add(int offset,
                byte b)
Add a segment matching the given byte offset bytes from the last segment.

Equivalent to:

    byte[] barray = new byte[1];
    barray[0] = b;
    match(offset, 1, barray, null);
 

add

public void add(int offset,
                short s)
Add a segment matching the given short offset bytes from the last segment.

XXX currently does not convert s to network order. Should it?


match

public void match(int offset,
                  int i)
Add a segment matching the given int offset bytes from the last segment.

XXX currently does not convert i to network order. Should it?


match

public void match(int offset,
                  long l)
Add a segment matching the given long offset bytes from the last segment.

XXX currently does not convert l to network order. Should it?


addETH

public void addETH(int offset,
                   int flags,
                   byte[] src,
                   byte[] dst,
                   short type)
Add a segment to match an Ethernet header.

Parameters:
offset - The offset from the previous segment.
flags - The flags that indicate which parameters should be ignored (i.e. wildcards).
src - The source address to match.
dst - The destination address to match.
type - The type of ethernet packet to match.

addIPv4

public void addIPv4(int offset,
                    int flags,
                    int source,
                    int srcMask,
                    int dest,
                    int dstMask,
                    byte protocol)
Add a segment to match an IPv4 header. Offset is the offset from the end of the previous segment (or from the beginning of the buffer for the first segment).

Use this instead of the vanilla match() to get a "payloadOffset" in the deliver func that will skip IP options. (A vanilla match() call will leave payloadOffset in the first byte after the "protocol" byte, which is not necessairly the first byte of the payload in an IP packet (e.g., one with options).

Parameters:
offset - the offset of the IPv4 header in the packet.
flags - The flags that indicate which parameters should be ignored (i.e. wildcards).
source - the 32-bit IPv4 source address to match in the header.
dest - the 32-bit IPv4 destination address to match in the header.
protocol - the 16-bit IPv4 protocol identifier.

addUDP

public void addUDP(int offset,
                   int srcPort,
                   int destPort)
Add a segment to match a UDP header, needs to be preceded by a call to matchIPv4.

addTCP

public void addTCP(int offset,
                   int srcPort,
                   int destPort)
Add a segment to match a TCP header, needs to be preceded by a call to matchIPv4.

addANEP

public void addANEP(int offset,
                    byte version,
                    boolean allVersions,
                    short protocolID)
Add a segment that matches an ANEP header.
Parameters:
version - The ANEP version number to match
allVersions - Match any version of ANEP
protocolID - The protocolID to match

matches

public final int matches(byte[] payload,
                         int payloadStart,
                         int payloadLength)
Test a packet to see if this key would match that packet.

XXX payloadLength has odd semantics. Either explain why, or fix the callers of this method.

Parameters:
payload - The packet data
payloadStart - The place to start matching in `payload'
payloadLength - The length of data in payload, including bytes up to payloadStart.
Returns:
0 if there was an error otherwise the index of the first byte after the end of the key.

length

public final int length()
Get the "length" of this key. The "length" of a key is the distance between the lowest absolute offset the key matches and the highest byte the key matches. For keys that include variable length components (e.g., addANEP() or addIPv4() were used), the value returned is just a guess.

toString

public java.lang.String toString()
Overrides:
toString in class edu.utah.janos.nodeos.pj_DemultiplexKey

JNodeOS v1.2.0 API

This documentation is Copyright (C) 1998-2002 The University of Utah. All Rights Reserved. See the file LICENSE for distribution terms.
Documentation, software, and mailing list archives for Janos can be found at the Janos Project web site: http://www.cs.utah.edu/flux/janos/
Generated on Mar 17, 2002