next up previous
Next: About this document ... Up: PACKET sockets Previous: Design

Implementation

The Linux packet processing engine has an important characteristic that lets us get away with the current hack to support packet sockets: packet processing elements for a packet are invoked on the same processor. Thus, there are no race conditions between processing elements as long as they are acting upon the same packet. We exploit this feature to define the following variable, which drives the sknid elevator:


\begin{lstlisting}
DEFINE_PER_CPU(int, sknid_elevator) = 0
\end{lstlisting}

An instance of this variable is defined globally for each processor, and is used by the packet processing elements to coordinate the reactivation of the packet socket handler.


\begin{lstlisting}
int *elevator=&__get_cpu_var(sknid_elevator);
int tag = skb->...
...g this packet. Mark it for elevation in xt_MARK */
}
return 0;
\end{lstlisting}

This fragment of code is extracted from the packet socket handler, af_packet.c. It decides if a given packet socket has access to the current packet. Notice the inside of the if condition. If a socket is not found to be qualified to see a packet, then it the elevator is activated.

When this packet arrives in the TCP/IP module and is handled by VNET+, VNET+ detects that the elevator is active and updates it to reflect the true credentials of the packet:


\begin{lstlisting}
curtag=&__get_cpu_var(sknid_elevator);
if (mark > 0 && *curtag==-2 && hooknum==NF_IP_LOCAL_IN)
{
*curtag = mark;
}
\end{lstlisting}

The sknid_elevator variable on the current processor contains the real xid of the current packet.

The packet dispatcher (we return to the passing on of packets to packet handlers) also recognizes this mark, and handles a packet differently if it sees it activated:


\begin{lstlisting}
if (pt_prev) {
if (*cur_elevator) {
/* The elevator is acti...
...{
/* Remember we upped its ref count? */
kfree_skb(skb);
}
}
\end{lstlisting}


next up previous
Next: About this document ... Up: PACKET sockets Previous: Design
2008-09-17