This function is used when updating the checksum of a packet we have modified. It is important to use this rather than recalculating the entire checksum, in case the previous checksum was invalid. In that case, we must take care not to make it correct.
Creates a hash from a TCP packet, which will then be used to reference the connection in the hash table. The hash should be the same for all packets in the connection.
Given a pointer to the beginning of a TCP option in a packet, return the length of the option. Either the option is known (NOP) and so the length can be returned straight away, or we check the following byte, which contains the length.
Here we determine whether the packet is a TCP packet or not. If it's not, we accept it without looking any further. If it is, we check for the TCP option containing p(q). We check all options, however the router module only ever inserts these as the first option, so it would be possible to look just at the first.If we find the option, the value is recorded in the global variable, global_pq, overwriting the existing value. Hence only the latest value is ever kept. global_pq is a 16-bit integer.
Note that okfn is included here only because it is a standard function type used by Netfilter. We don't have a choice which arguments which get.
if (skb pointer is NULL) return NF_ACCEPT Mark nfcache as NFC_UNKNOWN If (packet is not IP and TCP) return NF_ACCEPT ptr = beginning of options while (ptr < optionslength): if (header[ptr] == TCPO_QSIZE) record p(q) and return NF_ACCEPT ptr++ return NF_ACCEPT
We used the window updating algorithm given in "A Novel Algorithm for Receiver-Based Management of Low Bandwidth Access Links" by Stephen Hanly, Rami Mukhtar and Lachlan Andrew to update the window in outgoing packets. This is only used if we have a value for p(q), but no check is made to ensure p(q) is a recent copy. If p(q) has not been received, no modification is made and packets will contain the window given by the standard Linux TCP/IP stack.Obviously, only TCP packets will be modified here.
if (we don't know p(q)) return NF_ACCEPT if (skb == NULL) return NF_ACCEPT Mark skb->nfcache as NFC_UNKNOWN if (packet no IP and TCP) return NF_ACCEPT if (local socket not known) return NF_ACCEPT get connection state from conntrack if (connection == NEW or RELATED) create new info struct look for connection info if (info == NULL) return NF_ACCEPT Record timestamp for packet in cyclic array calculate window using client's algorithm Adjust for window scaling factor Change window field in packet Recompute checksum if (time to clean) clean hash table return NF_ACCEPT
Returns NULL if the skbuff could not be found. Otherwise a pointer to a &struct rami_info is returned;
Creates a new struct rami_info and initialises it with data from the sk_buff given.
Registers the netfilter hooks with netfilter. Once this is done, all outgoing and incoming packets to this computer will pass through one of check_pq (incoming) or modify_window (outgoing).
Unregisters the netfilter hooks.
This function searches through the hash table, and frees any connections which haven't been used for a while (ie. they haven't seen any packets)
While (haven't cleaned "cleaned" entries): pick next entry if entry hasn't been used for 1 hour: free entry incremement counter of cleaned entries