IPsec 관련 데이터 구조 1

저작권 성명: 필요 하 시 면 전재 할 수 있 지만 출처 를 밝 혀 주 십시오.https://blog.csdn.net/City_of_skey/article/details/86562770
목차
1. 소개
2、xfrm_state
3、xfrm_policy
4、xfrm_tmpl 
1. 소개
ipsec 데이터 암호 화 는 커 널 IP 층 에서 이 루어 집 니 다. PF 를 통 해INET 형식 소켓 과 응용 층 통신 파일 은 / net / key 디 렉 터 리 에서 보안 연맹 SA 와 보안 정책 SP 는 xfrm 데이터 베 이 스 를 통 해 이 루어 집 니 다.ESP, AH 프로 토 콜 에서 / net / ipv 4 디 렉 터 리 에서 이 루어 집 니 다.암호 화 알고리즘, 인증 알고리즘 은 crypto 디 렉 터 리 에서 실 현 됩 니 다.
다음은 각 파일 이 구현 하 는 기능 입 니 다.
net / xfrm 디 렉 터 리 에 있 는 파일 구현 기능 개:
xfrm_state. c: xfrm 상태 관리
xfrm_policy. c: xfrm 정책 관리
xfrm_알고리즘 관리
xfrm_해시 표 관리
xfrm_input. c: 안전 경로 처리, ipsec 패키지 처리
xfrm_user. c: netlink 인터페이스의 SA 와 SP 처리
net / ipv 4 디 렉 터 리 다음 파일 기능:
ah 4. c: ah 프로 토 콜 처리
esp4. c: esp 프로 토 콜 처리
ipcomp. c: ip 압축 프로 토 콜 처리
xfrm4_ipsec 패키지 처리
xfrm4_outp. c: ipv 4 의 ipsec 패키지 처 리 를 받 습 니 다.
xfrm4_state. c: ipv 4 의 SA 처리
xfrm4_policy. c: ipv 4 의 SP 처리
xfrm4_tunnel. c: ipv 4 채널 처리
xfrm4_mode_transport. c: 전송 모드 처리
xfrm4_mode_터널 모드 처리
xfrm4_mode_beet. c: beet 모드 처리
 
2、xfrm_state
struct xfrm_state 구조 체 관리 SA 상태, 각 요 소 는 다음 과 같이 정의 합 니 다.
/* Full description of state of transformer. */
struct xfrm_state {			/*SA     */
#ifdef CONFIG_NET_NS
	struct net		*xs_net;
#endif
	union {
		struct hlist_node	gclist;
		struct hlist_node	bydst;		/*       */
	};
	struct hlist_node	bysrc;		/*      */
	struct hlist_node	byspi;		/*spi   */

	atomic_t		refcnt;
	spinlock_t		lock;

	struct xfrm_id		id;			/*id  ,     、  ip、spi   */
	struct xfrm_selector	sel;		/*     */
	struct xfrm_mark	mark;		/*      */

	u32			genid;

	/* Key manager bits */
	struct xfrm_state_walk	km;

	/* Parameters of this state. */
	struct {
		u32		reqid;			/*  id*/
		u8		mode;			/*  ,    、    */
		u8		replay_window;	/*    */
		u8		aalgo, ealgo, calgo;/*  、  、    id*/
		u8		flags;			/*    */
		u16		family;			/*   */
		xfrm_address_t	saddr;	/*   */
		int		header_len;		/*       */
		int		trailer_len;
	} props;						/*SA  */

	struct xfrm_lifetime_cfg lft;		/*      */

	/* Data for transformer */
	struct xfrm_algo_auth	*aalg;	/*    */
	struct xfrm_algo	*ealg;		/*    */
	struct xfrm_algo	*calg;		/*    */
	struct xfrm_algo_aead	*aead;

	/* Data for encapsulator */
	struct xfrm_encap_tmpl	*encap;	/*NAT    */

	/* Data for care-of address */
	xfrm_address_t	*coaddr;

	/* IPComp needs an IPIP tunnel for handling uncompressed packets */
	struct xfrm_state	*tunnel;		/*  */

	/* If a tunnel, number of users + 1 */
	atomic_t		tunnel_users;	/*    */

	/* State for replay detection */
	struct xfrm_replay_state replay;	/*      */

	/* Replay detection state at the time we sent the last notification */
	struct xfrm_replay_state preplay;/*       */

	/* internal flag that only holds state for delayed aevent at the
	 * moment
	*/
	u32			xflags;		/*  */

	/* Replay detection notification settings */
	u32			replay_maxage;	/*        */
	u32			replay_maxdiff;	/*      */

	/* Replay detection notification timer */
	struct timer_list	rtimer;	/*       */

	/* Statistics */
	struct xfrm_stats	stats;	/*   */

	struct xfrm_lifetime_cur curlft;	/*     */
	struct tasklet_hrtimer	mtimer;

	/* Last used time */
	unsigned long		lastused;

	/* Reference to data common to all the instances of this
	 * transformer. */
	const struct xfrm_type	*type;	/*   ESP、AH、IPCOMP*/
	struct xfrm_mode	*inner_mode;/*  ,  、  */
	struct xfrm_mode	*inner_mode_iaf;
	struct xfrm_mode	*outer_mode;

	/* Security context */
	struct xfrm_sec_ctx	*security;	/*     */

	/* Private data of this transformer, format is opaque,
	 * interpreted by xfrm_type methods. */
	void			*data;		/*    */
};

3、xfrm_policy
struct xfrm_policy 구조 체 는 SP 를 정의 합 니 다. 각 요 소 는 다음 과 같이 정의 합 니 다.
struct xfrm_policy {
#ifdef CONFIG_NET_NS
	struct net		*xp_net;
#endif
	struct hlist_node	bydst;/*       */
	struct hlist_node	byidx;/* id   */

	/* This lock only affects elements except for entry. */
	rwlock_t		lock;
	atomic_t		refcnt;/*    */
	struct timer_list	timer;/*     */

	struct flow_cache_object flo;
	atomic_t		genid;
	u32			priority;/*     */
	u32			index;/*     */
	struct xfrm_mark	mark;
	struct xfrm_selector	selector;/*   */
	struct xfrm_lifetime_cfg lft;		/*      */
	struct xfrm_lifetime_cur curlft;	/*       */
	struct xfrm_policy_walk_entry walk;
	u8			type;	/*  */
	u8			action;	/*    ,  、  、  */
	u8			flags;	/*  */
	u8			xfrm_nr;	
	u16			family;/*  */
	struct xfrm_sec_ctx	*security;/*     */
	struct xfrm_tmpl       	xfrm_vec[XFRM_MAX_DEPTH];/*    */
};

4、xfrm_tmpl 
struct xfrm_tmpl 구조 체 는 템 플 릿 구조 체 로 SA 와 SP 의 조회 에 사 용 됩 니 다.
struct xfrm_tmpl {
/* id in template is interpreted as:
 * daddr - destination of tunnel, may be zero for transport mode.
 * spi   - zero to acquire spi. Not zero if spi is static, then
 *	   daddr must be fixed too.
 * proto - AH/ESP/IPCOMP
 */
	struct xfrm_id		id;		/*SA   :  ip、  、spi*/

/* Source address of tunnel. Ignored, if it is not a tunnel. */
	xfrm_address_t		saddr;	/*   */

	unsigned short		encap_family;

	u32			reqid;	/*  id*/	

/* Mode: transport, tunnel etc. */
	u8			mode;

/* Sharing mode: unique, this session only, this user only etc. */
	u8			share;

/* May skip this transfomration if no SA is found */
	u8			optional;

/* Skip aalgos/ealgos/calgos checks. */
	u8			allalgs;

/* Bit mask of algos allowed for acquisition */
	u32			aalgos;
	u32			ealgos;
	u32			calgos;
};

좋은 웹페이지 즐겨찾기