📄 ppp.c
字号:
{
struct ppp_pccb *ccb = &PPPpccb[unit];
struct ppp_cfg *ccp = &pppcfgtab[unit];
lcp_options *wo = &lcp_wantoptions[unit];
if (!wo->passive)
{
(*ccp->ifinfo->genifioctl)(lowerid[unit], CLOSELINK, 0);
}
else
{
lcp_open(unit);
}
ccb->pppstatus = PSDOWN;
return;
}
/*
* Set up the link and notify the lcp layer to start the negotiations.
*/
void SetupLink(int unit)
{
struct ppp_cfg *ccp = &pppcfgtab[unit];
(*ccp->ifinfo->genifioctl)(unit, SETUPLINK, 0);
return;
}
/*
* Shutdown the link and notify the lcp layer.
*/
void CloseLink(int unit)
{
struct ppp_pccb *ccb = &PPPpccb[unit];
lcp_options *wo = &lcp_wantoptions[unit];
wo->passive = 0;
ccb->pppstatus = PSDOWN;
ccb->mibstat.ifoperstatus = 2;
/* TODO: should this be lcp_lowerdown */
lcp_close(unit);
return;
}
/*
* ppp_timer: function to handle the timer functionality.
*
*/
void ppp_timer()
{
/* TODO: fix this timeout stuff */
alrm();
}
/* Bits in auth_pending[] */
#define UPAP_WITHPEER 1
#define UPAP_PEER 2
#define CHAP_WITHPEER 4
#define CHAP_PEER 8
static int auth_pending[NUM_PPP];
/*
* LCP has gone down; it will either die or try to re-establish.
*/
void
link_down(unit)
int unit;
{
ipcp_close(unit);
}
/*
* The link is established.
* Proceed to the Dead, Authenticate or Network phase as appropriate.
*/
void
link_established(unit)
int unit;
{
int auth;
lcp_options *wo = &lcp_wantoptions[unit];
lcp_options *go = &lcp_gotoptions[unit];
lcp_options *ho = &lcp_hisoptions[unit];
if (wo->neg_upap | wo->neg_chap) {
if (!(go->neg_chap | go->neg_upap)) {
syslog(LOG_INFO, "Require Authentication, Peer does not authenticate");
lcp_close(unit);
return;
}
}
auth = 0;
if (go->neg_chap) {
#if CHAPNEEDED
ChapAuthPeer(unit, hostname, (int) go->chap_mdtype);
auth |= CHAP_PEER;
#endif
} else if (go->neg_upap) {
#if UPAPNEEDED
upap_authpeer(unit);
auth |= UPAP_PEER;
#endif
}
if (ho->neg_chap) {
#if CHAPNEEDED
ChapAuthWithPeer(unit, hostname,(int) ho->chap_mdtype);
auth |= CHAP_WITHPEER;
#endif
} else if (ho->neg_upap) {
#if UPAPNEEDED
upap_authwithpeer(unit, pppcfgtab[unit].user, pppcfgtab[unit].passwd);
auth |= UPAP_WITHPEER;
#endif
}
auth_pending[unit] = auth;
if (!auth)
network_phase(unit);
}
/*
* Proceed to the network phase.
*/
static void
network_phase(unit)
int unit;
{
ipcp_open(unit);
}
static int prot;
/*
* The peer has failed to authenticate himself using `protocol'.
*/
void
auth_peer_fail(unit, protocol)
int unit, protocol;
{
prot = protocol;
/*
* Authentication failure: take the link down
*/
lcp_close(unit);
}
/*
* The peer has been successfully authenticated using `protocol'.
*/
void
auth_peer_success(unit, protocol)
int unit, protocol;
{
int bit;
switch (protocol) {
case PPP_CHAP:
bit = CHAP_PEER;
break;
case PPP_PAP:
bit = UPAP_PEER;
break;
default:
syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
protocol);
return;
}
/*
* If there is no more authentication still to be done,
* proceed to the network phase.
*/
if ((auth_pending[unit] &= ~bit) == 0) {
ipcp_open(unit);
}
}
/*
* We have successfully authenticated ourselves with the peer using `protocol'.
*/
void
auth_withpeer_success(unit, protocol)
int unit, protocol;
{
int bit;
switch (protocol) {
case PPP_CHAP:
bit = CHAP_WITHPEER;
break;
case PPP_PAP:
bit = UPAP_WITHPEER;
break;
default:
syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
protocol);
bit = 0;
}
/*
* If there is no more authentication still being done,
* proceed to the network phase.
*/
if ((auth_pending[unit] &= ~bit) == 0)
network_phase(unit);
}
void
auth_withpeer_fail(int a, int b) {
ppp_report_error((long)a, EAUTHFAIL);
}
void
sifdown(int unit)
{
PPPpccb[unit].pppstatus = PSDOWN;
SIFDOWN(unit); /* reset the NI */
}
int
sifup(int unit)
{
PPPpccb[unit].pppstatus = PSUP;
SIFUP(unit);
if (pppcfgtab[unit].dialmode == PPP_DEMANDDIAL) {
/* process output queue */
ppp_output(unit);
}
return(1);
}
void
cifaddr(int unit, u_int32_t ours, u_int32_t his)
{
CIFADDR(unit, ours, his);
}
int
sifaddr(int unit, u_int32_t ours, u_int32_t his, u_int32_t mask)
{
SIFADDR(unit, ours, his);
return(1);
}
void
sifvjcomp(int unit, int neg_vj, u_char cflag, u_char d)
{
PCI *pc = &pcis[unit];
pc->pci_flags |= ( neg_vj ? PCI_FLAGS_VJCOMP : 0);
pc->pci_flags |= ( cflag ? PCI_FLAGS_CID : 0);
}
u_int32_t
GetMask(u_int32_t a)
{
return(0);
}
unsigned short
MAX(unsigned short a, unsigned short b)
{
return((a > b) ? (a) : (b));
}
void
ppp_set_xaccm(int a, u_int32_t *b)
{
}
void
ppp_send_config(int unit,int mru ,int asyncmap,int pcomp, int acomp)
{
PAI *pa = &pais[unit];
PCI *pc = &pcis[unit];
SIFMTU(unit, mru);
PPPpccb[unit].usrmtu = mru;
pa->pai_asyncmap = asyncmap;
if (pcomp) SIFPCOMPRESSION(unit, 0);
if (acomp) SIFACCOMPRESSION(unit, 0);
PPPpccb[unit].mibstat.localmru = mru;
PPPpccb[unit].mibstat.sendaccmap = asyncmap;
PPPpccb[unit].mibstat.sendpcomp = pcomp;
PPPpccb[unit].mibstat.sendaccomp = acomp;
}
void
ppp_recv_config(int unit,int mru,int asyncmap,int pcomp, int acomp)
{
PPPpccb[unit].mibstat.remotemru = mru;
PPPpccb[unit].mibstat.recvaccmap = asyncmap;
PPPpccb[unit].mibstat.recvpcomp = pcomp;
PPPpccb[unit].mibstat.recvaccomp = acomp;
}
int auth_ip_addr(int a, u_int32_t b) {
return(1);
}
void
link_terminated(int unit)
{
ppp_exit(unit);
}
void
print_string(p, len, printer, arg)
u_char *p;
int len;
void (*printer) (void *, char *, ...);
void *arg;
{
int c;
printer(arg, "\"");
for (; len > 0; --len) {
c = *p++;
if (' ' <= c && c <= '~')
printer(arg, "%c", c);
else
printer(arg, "\\%.3o", c);
}
printer(arg, "\"");
}
int interfaceinit(int unit)
{
struct ppp_pccb *ccb = &PPPpccb[unit];
void *cfg = pppcfgtab[unit].IFconfig;
ifcfg[unit].callback = PPPcallback; /*ifcfg is */
ifcfg[unit].IFconfig = cfg;
return((*pppcfgtab[unit].ifinfo->genifopen)
(&ifcfg[unit], unit));
}
void PPPcallback(Uid uid, unsigned long cmd, void *arg) /*genif*/
{
unsigned long msg[4];
msg[1] = (unsigned long) uid;
switch(cmd)
{
case LINKUP:
msg[0] = MSG_LINKUP;
q_send(Qid, msg);
ev_send(Tid, PEV_QEVENT);
break;
case RCVDPKT:
AsyncDataInd(uid, arg, 0);
break;
case LINKCLOSE:
msg[0] = MSG_LINKCLOSE;
q_send(Qid, msg);
ev_send(Tid, PEV_QEVENT);
break;
case LINKDOWN:
msg[0] = MSG_LINKDOWN;
q_send(Qid, msg);
ev_send(Tid, PEV_QEVENT);
break;
case ERROR:
ppp_report_error((long)uid, (u_long)arg);
break;
default:
break;
}
}
void
signal_lowerup(int unit)
{
#if CHAPNEEDED
ChapLowerUp(unit); /* Enable CHAP */
#endif
#if UPAPNEEDED
upap_lowerup(unit); /* Enable UPAP */
#endif
ipcp_lowerup(unit); /* Enable IPCP */
}
void
signal_lowerdown(int unit)
{
ipcp_lowerdown(unit);
#if CHAPNEEDED
ChapLowerDown(unit);
#endif
#if UPAPNEEDED
upap_lowerdown(unit);
#endif
}
/* This is not supported yet */
void pppassert(int a) { }
void cifproxyarp(int a, u_int32_t b) { }
int sifproxyarp(int a, u_int32_t b) { }
void ccp_lowerup(int a) { }
void ccp_lowerdown(int a) { }
void link_required(int a) { }
int sifdefaultroute(int a, u_int32_t b){ }
int cifdefaultroute(int a, u_int32_t b){ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -