1. 初始化
int __init ip_vs_init(void)
{
/*初始化src服务ip_vs_svc_table和fwm服务ip_vs_svc_fwm_table*/
ip_vs_control_init();
/*初始化tcp ip_vs_protocol_tcp/udp ip_vs_protocol_udp/sctp协议处理函数 */
ip_vs_protocol_init();
/*初始化connection hash table: ip_vs_conn_tab*/
ip_vs_conn_init();
/*注册ip_vs netfilter钩子函数*/
nf_register_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
/*注册ip_vs_genl用户空间配置接口ip_vs_genl_ops*/
ip_vs_register_nl_ioctl();
}
2. 用户空间配置接口ip_vs_genl
const struct genl_ops ip_vs_genl_ops[] = {
{
/*添加虚服务, 还有set_service del_sevice*/
.cmd = IPVS_CMD_NEW_SERVICE,
.flags = GENL_ADMIN_PERM,
.policy = ip_vs_cmd_policy,
.doit = ip_vs_genl_set_cmd,
},
{
/*添加真实服务 还有set_service del_sevice*/
.cmd = IPVS_CMD_NEW_DEST,
.flags = GENL_ADMIN_PERM,
.policy = ip_vs_cmd_policy,
.doit = ip_vs_genl_set_cmd,
},
.......
};
# ipvsadm -A|E -t|u|f virutal-service-address:port [-s scheduler] [-p [timeout]] [-M netmask]
# ipvsadm -D -t|u|f virtual-service-address
struct ip_vs_service {
struct hlist_node s_list; /* for normal service table */
struct hlist_node f_list; /* for fwmark-based service table */
atomic_t refcnt; /* reference counter */
u16 af; /* address family */
__u16 protocol; /* which protocol (TCP/UDP) */
union nf_inet_addr addr; /* IP address for virtual service */
__be16 port; /* port number for the service */
__u32 fwmark; /* firewall mark of the service */
unsigned int flags; /* service status flags */
unsigned int timeout; /* persistent timeout in ticks */
struct list_head destinations; /* real server d-linked list */
__u32 num_dests; /* number of servers */
/* for scheduling */
struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
};