Wednesday, September 17, 2008

XFRM init procedure

Aka, xfrm initiate itself by two parts: initiate user operation and initiate sa/spd. So today I try to describe each one.

1. Initiate user operation(xfrm_user.c).
    As I mention before, xfrm use netlink or pfkey to communicate sadb-engine(may contains ike function, etc), and a overview of the relationship beween them. Here, we'll go a little deeper to see how the relationship build. Also, I still try to focus on netlink.If you're interesting in pfkey, try reading af_key.c code. Anyway xfrm can support both method at the same time.
    There're two key structure during the initiating: xfrm_km_list and xfrm_nl and they're global used. when we call "xfrm_register_km" the suit of netlink user operation , hold in the netlink_msr, add to the xfrm_km_list. Here is One example that if xfrm start "xfrm_lookup" and cannot find sa in the sa hash tables, it will go through the list to find the registered user operation suit and then aquire sa from sadb-engine. yeah, pfkey does the same way.well, xfrm_nl is a "struct sock*" type, which yields after calling "netlink_kernel_create", and it'll be used to retrieve sadb-engine user socket, which are created in linux user space, and pass down message to each one.

2. Initiate sa/spd hash tables and operation family.
    The very start of xfrm may be from "ip_rt_init", which commence two function: xfrm_init and xfrm4_init. "xfrm_init" initiate sa and spd hash tables and some housekeeper, and xfrm4_init does something with sa/spd's really operation. later during analsing the point A to point D, I will go detail nearly in each one.