2008年7月11日 星期五

研發筆記-PPP如何新增options

/bin/pppd name test password testtest ...
上面這一串所說的就是以pppd連線,帳號是test,密碼是testtest。
很明顯的options就是name跟password,但我們有辦法加自己要用的option嗎?

答案是可以的!
以ip-up的script為例,ppp-2.4.3並沒有預留option讓我們輸入ip-up, ip-down的script,只能使用/etc/ppp下面的ip-up, ip-down script.
因此我們只能自己動手腳加了!
舉例來說:
我們可以參照auth.c的option_t auth_options[];

option_t auth_options[] = {
{ "auth", o_bool, &auth_required,
"Require authentication from peer", OPT_PRIO | 1 },
{ "noauth", o_bool, &auth_required,
"Don't require peer to authenticate", OPT_PRIOSUB | OPT_PRIV,
&allow_any_ip },
{ "require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
"Require PAP authentication from peer",
...
...
{ "name", o_string, our_name,
"Set local name for authentication",
OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXNAMELEN },


{ "+ua", o_special, (void *)setupapfile,
"Get PAP user and password from file",
OPT_PRIO | OPT_A2STRVAL, &uafname },

{ "user", o_string, user,
"Set name for auth with peer", OPT_PRIO | OPT_STATIC, NULL, MAXNAMELEN },

{ "password", o_string, passwd,
"Password for authenticating us to the peer",
OPT_PRIO | OPT_STATIC | OPT_HIDE, NULL, MAXSECRETLEN },


就可以看到我們熟悉的name跟password這兩個option。

在ipcp.c裡面,有一個ipcp_option_list的structure list.
static option_t ipcp_option_list[] = {
{ "noip", o_bool, &ipcp_protent.enabled_flag,
"Disable IP and IPCP" },
{ "-ip", o_bool, &ipcp_protent.enabled_flag,
"Disable IP and IPCP", OPT_ALIAS },

{ "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
"Disable VJ compression", OPT_A2CLR, &ipcp_allowoptions[0].neg_vj },

...
...
{ "IP addresses", o_wild, (void *) &setipaddr,
"set local and remote IP addresses",
OPT_NOARG | OPT_A2PRINTER, (void *) &printipaddr },
{ "ip-up", o_string, &ip_up,
"ip-up script path", OPT_PRIV},
{ "ip-down", o_string, &ip_down,
"ip-up script path", OPT_PRIV},

{ NULL }
};

由於我們要的只是字串,因此相對簡單,只要在ipcp的option list加上ip-up,ip-down兩個structure就好。

0 意見: