ppp: pass -i flag to ip/ipconfig (-i for ipv4, -I for ipv6) to populate ipnet= entries

This commit is contained in:
cinap_lenrek 2024-10-28 19:08:23 +00:00
parent 5f59652ae1
commit 6894c4e13a
3 changed files with 61 additions and 7 deletions

View file

@ -9,6 +9,13 @@ ppp, pppoe, pptp, pptpd \- point-to-point protocol
.B -b
.I baud
] [
] [
.B -i
.I ipnet
] [
.B -I
.I ipnet
] [
.B -k
.I keyspec
] [
@ -48,6 +55,12 @@ ppp, pppoe, pptp, pptpd \- point-to-point protocol
.B -U
.I duid
] [
.B -i
.I ipnet
] [
.B -I
.B ipnet
] [
.B -k
.I keyspec
] [
@ -129,6 +142,20 @@ disallow IP header compression
make PPP add HDLC framing. This is necessary when using
PPP over a serial line or a TCP connection
.TP
.B i
when writing IPv4 configuration to
.BR /net/ndb ,
create a
.B ipnet=
tuple with the value of
.I ipnet
and the network attributes.
.TP
.B I
same as
.B -i
but for IPv6.
.TP
.B k
add
.I keyspec

View file

@ -26,6 +26,8 @@ static char *chatfile;
int debug;
char* LOG = "ppp";
char* keyspec = "";
char* ipnet4;
char* ipnet6;
/*
* Calculate FCS - rfc 1331
@ -1573,9 +1575,11 @@ ppptimer(PPP *ppp)
}
static void
ipconfig(int shell, char *net, char *dev, int mtu, int proxy, Ipaddr gate, Ipaddr dns[2], char *duid)
ipconfig(int shell, char *net, char *dev, char *ipnet, int mtu, int proxy, Ipaddr gate, Ipaddr dns[2], char *duid)
{
fprint(shell, "ip/ipconfig -x %q ", net);
if(debug)
fprint(shell, "-D ");
if(!primary){
/* don't write /net/ndb */
fprint(shell, "-P ");
@ -1592,6 +1596,8 @@ ipconfig(int shell, char *net, char *dev, int mtu, int proxy, Ipaddr gate, Ipadd
/* set default gateway */
if(gate != nil)
fprint(shell, "-g %I ", gate);
if(ipnet != nil)
fprint(shell, "-i %s ", ipnet);
}
/* allow dhcpv6 */
if(duid != nil)
@ -1607,10 +1613,10 @@ static void
addip(int shell, char *net, char *dev, Ipaddr local, Ipaddr remote, int mtu, Ipaddr *dns)
{
if(validv4(local) && validv4(remote)){
ipconfig(shell, net, dev, mtu, proxy, remote, dns, nil);
ipconfig(shell, net, dev, ipnet4, mtu, proxy, remote, dns, nil);
fprint(shell, "add %I 255.255.255.255 %I\n", local, remote);
} else if(validv6(local)){
ipconfig(shell, net, dev, mtu, 0, nil, nil, nil);
ipconfig(shell, net, dev, ipnet6, mtu, 0, nil, nil, nil);
fprint(shell, "add %I /64\n", local);
}
}
@ -1619,10 +1625,10 @@ static void
delip(int shell, char *net, char *dev, Ipaddr local, Ipaddr remote)
{
if(validv4(local) && validv4(remote)){
ipconfig(shell, net, dev, 0, 0, remote, nil, nil);
ipconfig(shell, net, dev, ipnet4, 0, 0, remote, nil, nil);
fprint(shell, "del %I 255.255.255.255\n", local);
} else if(validv6(local)){
ipconfig(shell, net, dev, 0, 0, nil, nil, nil);
ipconfig(shell, net, dev, ipnet6, 0, 0, nil, nil, nil);
fprint(shell, "del %I /64\n", local);
}
}
@ -1632,7 +1638,7 @@ v6autoconfig(int shell, char *net, char *dev, Ipaddr remote, char *duid)
{
if(server || !validv6(remote))
return;
ipconfig(shell, net, dev, 0, proxy, remote, nil, duid);
ipconfig(shell, net, dev, ipnet6, 0, proxy, remote, nil, duid);
fprint(shell, "ra6 recvra 1\n");
}
@ -2810,7 +2816,7 @@ int interactive;
void
usage(void)
{
fprint(2, "usage: ppp [-CPSacdfuy] [-b baud] [-k keyspec] [-m mtu] "
fprint(2, "usage: ppp [-CPSacdfuy] [-b baud] [-iI ipnet] [-k keyspec] [-m mtu] "
"[-M chatfile] [-p dev] [-x netmntpt] [-t modemcmd] [-U duid] "
"[local-addr [remote-addr]]\n");
exits("usage");
@ -2870,6 +2876,12 @@ main(int argc, char **argv)
case 'F':
pppframing = 0;
break;
case 'i':
ipnet4 = EARGF(usage());
break;
case 'I':
ipnet6 = EARGF(usage());
break;
case 'k':
keyspec = EARGF(usage());
break;

View file

@ -21,6 +21,7 @@ int debug;
int rflag;
int sessid;
char *duid;
char *ipnet4, *ipnet6;
char *keyspec;
char *pppnetmtpt;
char *acname;
@ -97,6 +98,12 @@ main(int argc, char **argv)
case 'm':
mtu = atoi(EARGF(usage()));
break;
case 'i':
ipnet4 = EARGF(usage());
break;
case 'I':
ipnet6 = EARGF(usage());
break;
case 'k':
keyspec = EARGF(usage());
break;
@ -643,6 +650,14 @@ execppp(int fd)
argv[argc++] = "-x";
argv[argc++] = pppnetmtpt;
}
if(ipnet4){
argv[argc++] = "-i";
argv[argc++] = ipnet4;
}
if(ipnet6){
argv[argc++] = "-I";
argv[argc++] = ipnet6;
}
if(keyspec){
argv[argc++] = "-k";
argv[argc++] = keyspec;