ppp: set source specific default route regardless of primary flag, set link speed thru new ctl message when -b is specified

This commit is contained in:
cinap_lenrek 2018-05-10 19:36:14 +02:00
parent 298f239695
commit eb3951bcd4
3 changed files with 24 additions and 7 deletions

View file

@ -53,6 +53,10 @@ ppp, pppoe, pptp, pptpd \- point-to-point protocol
.I mtu .I mtu
] ]
[ [
.B -b
.I baud
]
[
.B -x .B -x
.I pppnetmntpt .I pppnetmntpt
] ]

View file

@ -1497,7 +1497,7 @@ ppptimer(PPP *ppp)
} }
static void static void
setdefroute(char *net, Ipaddr gate) defroute(char *net, char *verb, Ipaddr gate, Ipaddr local)
{ {
int fd; int fd;
char path[128]; char path[128];
@ -1506,7 +1506,10 @@ setdefroute(char *net, Ipaddr gate)
fd = open(path, ORDWR); fd = open(path, ORDWR);
if(fd < 0) if(fd < 0)
return; return;
fprint(fd, "add 0 0 %I", gate); fprint(fd, "tag ppp");
if(primary)
fprint(fd, "%s 0.0.0.0 0.0.0.0 %I", verb, gate);
fprint(fd, "%s 0.0.0.0 0.0.0.0 %I %I 255.255.255.255", verb, gate, local);
close(fd); close(fd);
} }
@ -1550,8 +1553,9 @@ ipopen(PPP *ppp)
close(cfd); close(cfd);
return "can't set addresses"; return "can't set addresses";
} }
if(primary) if(baud)
setdefroute(ppp->net, ppp->remote); fprint(cfd, "speed %d", baud);
defroute(ppp->net, "add", ppp->remote, ppp->local);
ppp->ipfd = fd; ppp->ipfd = fd;
ppp->ipcfd = cfd; ppp->ipcfd = cfd;
@ -1570,6 +1574,7 @@ ipopen(PPP *ppp)
/* we may have changed addresses */ /* we may have changed addresses */
if(ipcmp(ppp->local, ppp->curlocal) != 0 || if(ipcmp(ppp->local, ppp->curlocal) != 0 ||
ipcmp(ppp->remote, ppp->curremote) != 0){ ipcmp(ppp->remote, ppp->curremote) != 0){
defroute(ppp->net, "remove", ppp->curremote, ppp->curlocal);
snprint(buf, sizeof buf, "remove %I 255.255.255.255 %I", snprint(buf, sizeof buf, "remove %I 255.255.255.255 %I",
ppp->curlocal, ppp->curremote); ppp->curlocal, ppp->curremote);
if(fprint(ppp->ipcfd, "%s", buf) < 0) if(fprint(ppp->ipcfd, "%s", buf) < 0)
@ -1578,6 +1583,7 @@ ipopen(PPP *ppp)
ppp->local, ppp->remote, ppp->mtu-10); ppp->local, ppp->remote, ppp->mtu-10);
if(fprint(ppp->ipcfd, "%s", buf) < 0) if(fprint(ppp->ipcfd, "%s", buf) < 0)
syslog(0, "ppp", "can't %s: %r", buf); syslog(0, "ppp", "can't %s: %r", buf);
defroute(ppp->net, "add", ppp->remote, ppp->local);
} }
syslog(0, "ppp", "%I/%I -> %I/%I", ppp->curlocal, ppp->curremote, syslog(0, "ppp", "%I/%I -> %I/%I", ppp->curlocal, ppp->curremote,
ppp->local, ppp->remote); ppp->local, ppp->remote);
@ -2634,7 +2640,7 @@ usage(void)
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
int mtu, baud, framing, user, mediain, mediaout, cfd; int mtu, framing, user, mediain, mediaout, cfd;
Ipaddr ipaddr, remip; Ipaddr ipaddr, remip;
char *dev, *modemcmd; char *dev, *modemcmd;
char net[128]; char net[128];
@ -2654,7 +2660,6 @@ main(int argc, char **argv)
invalidate(remip); invalidate(remip);
mtu = Defmtu; mtu = Defmtu;
baud = 0;
framing = 0; framing = 0;
setnetmtpt(net, sizeof(net), nil); setnetmtpt(net, sizeof(net), nil);
user = 0; user = 0;

View file

@ -29,11 +29,12 @@ int cookielen;
uchar etherdst[6]; uchar etherdst[6];
int mtu = 1492; int mtu = 1492;
int pktcompress, hdrcompress; int pktcompress, hdrcompress;
char *baud;
void void
usage(void) usage(void)
{ {
fprint(2, "usage: pppoe [-PdcC] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-x pppnet] [ether0]\n"); fprint(2, "usage: pppoe [-PdcC] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-b baud] [-x pppnet] [ether0]\n");
exits("usage"); exits("usage");
} }
@ -76,6 +77,9 @@ main(int argc, char **argv)
case 'k': case 'k':
keyspec = EARGF(usage()); keyspec = EARGF(usage());
break; break;
case 'b':
baud = EARGF(usage());
break;
case 'c': case 'c':
pktcompress = 1; pktcompress = 1;
break; break;
@ -533,6 +537,10 @@ execppp(int fd)
argv[argc++] = "-d"; argv[argc++] = "-d";
if(primary) if(primary)
argv[argc++] = "-P"; argv[argc++] = "-P";
if(baud){
argv[argc++] = "-b";
argv[argc++] = baud;
}
if(hdrcompress) if(hdrcompress)
argv[argc++] = "-C"; argv[argc++] = "-C";
if(pktcompress) if(pktcompress)