2 * Copyright (c) 1997, 2001 Joerg Wunsch
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sbin/spppcontrol/spppcontrol.c,v 1.7.2.2 2002/04/24 18:47:22 joerg Exp $
27 * $DragonFly: src/sbin/spppcontrol/spppcontrol.c,v 1.3 2003/08/08 06:18:41 dillon Exp $
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
32 #include <sys/socket.h>
35 #include <net/if_var.h>
36 #include <net/sppp/if_sppp.h>
45 static void usage(void);
46 void print_vals(const char *ifname
, struct spppreq
*sp
);
47 const char *phase_name(enum ppp_phase phase
);
48 const char *proto_name(u_short proto
);
49 const char *authflags(u_short flags
);
51 #define PPP_PAP 0xc023
52 #define PPP_CHAP 0xc223
55 main(int argc
, char **argv
)
58 int errs
= 0, verbose
= 0;
62 const char *ifname
, *cp
;
66 while ((c
= getopt(argc
, argv
, "v")) != -1)
83 strncpy(ifr
.ifr_name
, ifname
, sizeof ifr
.ifr_name
);
85 /* use a random AF to create the socket */
86 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
87 err(EX_UNAVAILABLE
, "ifconfig: socket");
92 spr
.cmd
= (int)SPPPIOGDEFS
;
93 ifr
.ifr_data
= (caddr_t
)&spr
;
95 if (ioctl(s
, SIOCGIFGENERIC
, &ifr
) == -1)
96 err(EX_OSERR
, "SIOCGIFGENERIC(SPPPIOGDEFS)");
100 print_vals(ifname
, &spr
);
104 #define startswith(s) strncmp(argv[0], s, (off = strlen(s))) == 0
107 if (startswith("authproto=")) {
109 if (strcmp(cp
, "pap") == 0)
110 spr
.defs
.myauth
.proto
=
111 spr
.defs
.hisauth
.proto
= PPP_PAP
;
112 else if (strcmp(cp
, "chap") == 0)
113 spr
.defs
.myauth
.proto
=
114 spr
.defs
.hisauth
.proto
= PPP_CHAP
;
115 else if (strcmp(cp
, "none") == 0)
116 spr
.defs
.myauth
.proto
=
117 spr
.defs
.hisauth
.proto
= 0;
119 errx(EX_DATAERR
, "bad auth proto: %s", cp
);
120 } else if (startswith("myauthproto=")) {
122 if (strcmp(cp
, "pap") == 0)
123 spr
.defs
.myauth
.proto
= PPP_PAP
;
124 else if (strcmp(cp
, "chap") == 0)
125 spr
.defs
.myauth
.proto
= PPP_CHAP
;
126 else if (strcmp(cp
, "none") == 0)
127 spr
.defs
.myauth
.proto
= 0;
129 errx(EX_DATAERR
, "bad auth proto: %s", cp
);
130 } else if (startswith("myauthname="))
131 strncpy(spr
.defs
.myauth
.name
, argv
[0] + off
,
133 else if (startswith("myauthsecret=") ||
134 startswith("myauthkey="))
135 strncpy(spr
.defs
.myauth
.secret
, argv
[0] + off
,
137 else if (startswith("hisauthproto=")) {
139 if (strcmp(cp
, "pap") == 0)
140 spr
.defs
.hisauth
.proto
= PPP_PAP
;
141 else if (strcmp(cp
, "chap") == 0)
142 spr
.defs
.hisauth
.proto
= PPP_CHAP
;
143 else if (strcmp(cp
, "none") == 0)
144 spr
.defs
.hisauth
.proto
= 0;
146 errx(EX_DATAERR
, "bad auth proto: %s", cp
);
147 } else if (startswith("hisauthname="))
148 strncpy(spr
.defs
.hisauth
.name
, argv
[0] + off
,
150 else if (startswith("hisauthsecret=") ||
151 startswith("hisauthkey="))
152 strncpy(spr
.defs
.hisauth
.secret
, argv
[0] + off
,
154 else if (strcmp(argv
[0], "callin") == 0)
155 spr
.defs
.hisauth
.flags
|= AUTHFLAG_NOCALLOUT
;
156 else if (strcmp(argv
[0], "always") == 0)
157 spr
.defs
.hisauth
.flags
&= ~AUTHFLAG_NOCALLOUT
;
158 else if (strcmp(argv
[0], "norechallenge") == 0)
159 spr
.defs
.hisauth
.flags
|= AUTHFLAG_NORECHALLENGE
;
160 else if (strcmp(argv
[0], "rechallenge") == 0)
161 spr
.defs
.hisauth
.flags
&= ~AUTHFLAG_NORECHALLENGE
;
162 else if (startswith("lcp-timeout=")) {
164 to
= strtol(cp
, &endp
, 10);
165 if (*cp
== '\0' || *endp
!= '\0' ||
167 * NB: 10 ms is the minimal possible value for
168 * hz=100. We assume no kernel has less clock
169 * frequency than that...
171 to
< 10 || to
> 20000)
172 errx(EX_DATAERR
, "bad lcp timeout value: %s",
174 spr
.defs
.lcp
.timeout
= to
;
175 } else if (strcmp(argv
[0], "enable-vj") == 0)
176 spr
.defs
.enable_vj
= 1;
177 else if (strcmp(argv
[0], "disable-vj") == 0)
178 spr
.defs
.enable_vj
= 0;
179 else if (strcmp(argv
[0], "enable-ipv6") == 0)
180 spr
.defs
.enable_ipv6
= 1;
181 else if (strcmp(argv
[0], "disable-ipv6") == 0)
182 spr
.defs
.enable_ipv6
= 0;
184 errx(EX_DATAERR
, "bad parameter: \"%s\"", argv
[0]);
190 spr
.cmd
= (int)SPPPIOSDEFS
;
192 if (ioctl(s
, SIOCSIFGENERIC
, &ifr
) == -1)
193 err(EX_OSERR
, "SIOCSIFGENERIC(SPPPIOSDEFS)");
196 print_vals(ifname
, &spr
);
204 fprintf(stderr
, "%s\n%s\n",
205 "usage: spppcontrol [-v] ifname [{my|his}auth{proto|name|secret}=...]",
206 " spppcontrol [-v] ifname callin|always");
211 print_vals(const char *ifname
, struct spppreq
*sp
)
213 printf("%s:\tphase=%s\n", ifname
, phase_name(sp
->defs
.pp_phase
));
214 if (sp
->defs
.myauth
.proto
) {
215 printf("\tmyauthproto=%s myauthname=\"%.*s\"\n",
216 proto_name(sp
->defs
.myauth
.proto
),
217 AUTHNAMELEN
, sp
->defs
.myauth
.name
);
219 if (sp
->defs
.hisauth
.proto
) {
220 printf("\thisauthproto=%s hisauthname=\"%.*s\"%s\n",
221 proto_name(sp
->defs
.hisauth
.proto
),
222 AUTHNAMELEN
, sp
->defs
.hisauth
.name
,
223 authflags(sp
->defs
.hisauth
.flags
));
225 printf("\tlcp-timeout=%d ms\n", sp
->defs
.lcp
.timeout
);
226 printf("\t%sable-vj\n", sp
->defs
.enable_vj
? "en": "dis");
227 printf("\t%sable-ipv6\n", sp
->defs
.enable_ipv6
? "en": "dis");
231 phase_name(enum ppp_phase phase
)
234 case PHASE_DEAD
: return "dead";
235 case PHASE_ESTABLISH
: return "establish";
236 case PHASE_TERMINATE
: return "terminate";
237 case PHASE_AUTHENTICATE
: return "authenticate";
238 case PHASE_NETWORK
: return "network";
244 proto_name(u_short proto
)
248 case PPP_PAP
: return "pap";
249 case PPP_CHAP
: return "chap";
251 sprintf(buf
, "0x%x", (unsigned)proto
);
256 authflags(u_short flags
)
260 if (flags
& AUTHFLAG_NOCALLOUT
)
261 strcat(buf
, " callin");
262 if (flags
& AUTHFLAG_NORECHALLENGE
)
263 strcat(buf
, " norechallenge");