라우팅 캐시 구조체

프로그래밍 | 2009/05/27 17:02 | letsme
리눅스 커널의 라우팅 캐시(Routing cache) 관련 구조체 struct rtable 은 다음과 같은 구조를 가지고 있습니다.

struct rtable

The Linux Networking Architecture 참고




struct rtable 구조체 안에 struct dst_entry 라는 자료구조를 포함하고 있는데 dst_entry 는 라우팅 후 패킷을 포워딩하기 위한 정보들을 담고 있는 구조체로서 하나의 rtable 마다 하나의 dst_entry를 가지게 됩니다.

rtable 구조체는 커널 2.6.20.21에서 다음과 같은 모양을 하고 있습니다.

include/net/route.h

struct rtable
{
    union
    {   
        struct dst_entry    dst;
        struct rtable       *rt_next;
    } u;

    struct in_device    *idev;
    
    unsigned        rt_flags;
    __u16           rt_type;
    __u16           rt_multipath_alg;

    __be32          rt_dst; /* Path destination */
    __be32          rt_src; /* Path source      */
    int         rt_iif;

    /* Info on neighbour */
    __be32          rt_gateway;

    /* Cache lookup keys */
    struct flowi        fl;

    /* Miscellaneous cached information */
    __be32          rt_spec_dst; /* RFC1122 specific destination */
    struct inet_peer    *peer; /* long-living peer info */
};

코드에서 보는 바와 같이 rtable 안에 dst_entry 구조체와 rtable의 next 포인터가 union으로 선언되어 있기 때문에 rtable 의 구조체의 포인터나 dst_entry의 포인터중 어떤 것을 알고 있더라도 상호참조가 가능합니다.

ps.
최근 커널에서는 union이 사라지고 rtable 구조체의 필드로 dst_entry가 들어가 있네요.
이전 1 2 3 4 5 ... 42 다음