Title: udp_fd / udp_fd_table[]

udp file descriptors (udp_fd's) make up udp_fd_table[]. When a process opens up a udp device file (e.g., /dev/udp), an element in udp_fd_table[] is set up. Many udp file descriptors are associated with each udp physical port (elements in udp_port_table[]). On the other hand, there is a 1:1 ratio between udp physical ports and ip file descriptors (elements in ip_fd_table[]).

typedef struct udp_fd

int uf_flags;
udp_port_t *uf_port;
ioreq_t uf_ioreq;
int uf_srfd;
nwio_udpopt_t uf_udpopt;
get_userdata_t uf_get_userdata;
put_userdata_t uf_put_userdata;
acc_t *uf_rdbuf_head;
acc_t *uf_rdbuf_tail;
size_t uf_rd_count;
size_t uf_wr_count;
time_t uf_exp_tim;
struct udp_fd *uf_port_next;
} udp_fd_t;

typedef struct nwio_udpopt
unsigned long nwuo_flags;
udpport_t nwuo_locport;
udpport_t nwuo_remport;
ipaddr_t nwuo_locaddr;
ipaddr_t nwuo_remaddr;
} nwio_udpopt_t;

int uf_flags:

uf_flags is a combination of the following flags:

#define UFF_EMPTY 0x0
#define UFF_INUSE 0x1
#define UFF_IOCTL_IP 0x2
#define UFF_READ_IP 0x4
#define UFF_WRITE_IP 0x8
#define UFF_OPTSET 0x10

uf_flags for all the udp file descriptors is initialized to UFF_EMPTY. When the udp file descipriptor is opened, uf_flags is set to UFF_INUSE and will remain so until the udp file descriptor is closed. After the udp file descriptor is opened, udp_ioctl() is called to configure the file descriptor, during which time the UFF_IOCTL_IP flag is set.

If a read request is received and cannot be immediately satisifed, UFF_READ_IP is set. However, all write requests are handled immediately and therefore the UFF_WRITE_IP flag is not important.

udp_port_t *uf_port:

uf_port is the udp physical port number that corresponds with this udp file descriptor. If /dev/udp0 was opened, uf_port will be a pointer to udp_port_table[0]. If /dev/udp1 was opened, uf_port will be a pointer to udp_port_table[1].

ioreq_t uf_ioreq:

If an ioctl request is made of the udp file descriptor (for example, a request to configure the file descriptor), uf_ioreq is set to the request. The different values that uf_ioreq can be are NWIOSUDPOPT (Set UDP OPTions) and NWIOGUDPOPT (Get UDP OPTions). The value of uf_ioreq is contained within a message received by the file system.

int uf_srfd:

The udp file descriptor's associated slot in sr_fd_table[].

nwio_udpopt_t uf_udpopt: (see below)
get_userdata_t uf_get_userdata:
put_userdata_t uf_put_userdata:

uf_get_userdata and uf_put_userdata are set to sr_get_userdata() and sr_put_userdata(), respectively. These values were passed in as arguments in sr_open().

acc_t *uf_rdbuf_head:
acc_t *uf_rdbuf_tail:

uf_rdbuf_head is the head and uf_rdbuf_tail is the tail of the udp file descriptor's read queue. Packets destined for the udp file descriptor are passed up from the lower layers (e.g., from the ethernet code to the ip code and finally to this queue). udp_read() eventually reads from this queue.

size_t uf_rd_count:
size_t uf_wr_count:

The number of bytes requested in a read/write request.

uf_rd_count is the number of bytes requested to be read from the read queue (see uf_rdbuf_head/uf_rdbuf_tail above) and uf_wr_count is the number of bytes requested to be written to lower layers (e.g., the ip code).

time_t uf_exp_tim:

When the read queue of a udp file descriptor is empty and a packet is placed in the queue, the timer (uf_exp_tim) is set. If this timer expires before the packet is read, this packet and all packets that have been subsequently to the read queue are discarded.

struct udp_fd *uf_port_next:

When a udp file descriptor is opened, hash_fd() places the file descriptor in a linked list. uf_port_next links the file descriptor to the next file descriptor in the linked list.

unsigned long nwuo_flags:
udpport_t nwuo_locport:
udpport_t nwuo_remport:
ipaddr_t nwuo_locaddr:
ipaddr_t nwuo_remaddr:

NWUO_RA_SET and NWUO_RP_SET specify that the Remote Address (RA) and the Remote Port (RP) are set for the udp file descriptor and that all packets written to the udp file descriptor are sent to the address/port nwuo_remaddr/nwuo_remport.

If the NWUO_LP_ANY flag is set, the port specified in the outgoing udp header is the port specified in the pseudo udp header that is written to the udp file descriptor along with the payload data. Otherwise, the port is taken from the udp file descriptor's configuration (specifically, the file descriptor's nwuo_locport field).

From ip(4):

"NWUO_RA_SET sets the remote IP address the value of nwuo_remaddr. Only packets from that address will be delivered and all packets will be sent to that address."

"NWUO_RP_SET sets the remote UDP port to the value of nwuo_remport. Only packets with a matching remote port will be delivered and all packets will be sent to that port."

"NWUO_LP_SEL requests the server to pick a port. This port will be in the range from 32768 to 65535 and it will be unique. NWUO_LP_SET sets the local port to the value of the nwuo_locport field. NWUO_LP_ANY does not select a port. Reception of data is therefore not possible but it is possible to send data."

These fields are set during the udp file descriptor's configuration.