Deleted Added
full compact
netgraph.c (122758) netgraph.c (134789)
1/*-
2 * Copyright (c) 2000 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/ppp/netgraph.c 122758 2003-11-15 15:26:35Z harti $
26 * $FreeBSD: head/usr.sbin/ppp/netgraph.c 134789 2004-09-05 01:46:52Z brian $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <sys/un.h>
32#include <netinet/in.h>
33#include <arpa/inet.h>
34#include <netdb.h>

--- 58 unchanged lines hidden (view full) ---

93 int cs; /* Control socket */
94 char hook[NG_HOOKSIZ]; /* Our socket node hook */
95};
96
97#define device2ng(d) ((d)->type == NG_DEVICE ? (struct ngdevice *)d : NULL)
98#define NG_MSGBUFSZ 4096
99#define NETGRAPH_PREFIX "netgraph:"
100
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <sys/un.h>
32#include <netinet/in.h>
33#include <arpa/inet.h>
34#include <netdb.h>

--- 58 unchanged lines hidden (view full) ---

93 int cs; /* Control socket */
94 char hook[NG_HOOKSIZ]; /* Our socket node hook */
95};
96
97#define device2ng(d) ((d)->type == NG_DEVICE ? (struct ngdevice *)d : NULL)
98#define NG_MSGBUFSZ 4096
99#define NETGRAPH_PREFIX "netgraph:"
100
101int
101unsigned
102ng_DeviceSize(void)
103{
104 return sizeof(struct ngdevice);
105}
106
107static int
102ng_DeviceSize(void)
103{
104 return sizeof(struct ngdevice);
105}
106
107static int
108ng_MessageOut(struct ngdevice *dev, struct physical *p, const char *data)
108ng_MessageOut(struct ngdevice *dev, const char *data)
109{
110 char path[NG_PATHSIZ];
109{
110 char path[NG_PATHSIZ];
111 int len, pos, dpos;
112 char *fmt;
111 char *fmt;
112 size_t len;
113 int pos, dpos;
113
114 /*
115 * We expect a node path, one or more spaces, a command, one or more
116 * spaces and an ascii netgraph structure.
117 */
118 data += strspn(data, " \t");
119 len = strcspn(data, " \t");
120 if (len >= sizeof path) {

--- 15 unchanged lines hidden (view full) ---

136 dev->dev.name, len + 4, strerror(errno));
137 return 0;
138 }
139
140 /*
141 * This is probably a waste of time, but we really don't want to end
142 * up stuffing unexpected % escapes into the kernel....
143 */
114
115 /*
116 * We expect a node path, one or more spaces, a command, one or more
117 * spaces and an ascii netgraph structure.
118 */
119 data += strspn(data, " \t");
120 len = strcspn(data, " \t");
121 if (len >= sizeof path) {

--- 15 unchanged lines hidden (view full) ---

137 dev->dev.name, len + 4, strerror(errno));
138 return 0;
139 }
140
141 /*
142 * This is probably a waste of time, but we really don't want to end
143 * up stuffing unexpected % escapes into the kernel....
144 */
144 for (pos = dpos = 0; pos < len;) {
145 for (pos = dpos = 0; pos < (int)len;) {
145 if (data[dpos] == '%')
146 fmt[pos++] = '%';
147 fmt[pos++] = data[dpos++];
148 }
149 strcpy(fmt + pos, " %s");
150 data += dpos;
151
152 data += strspn(data, " \t");

--- 11 unchanged lines hidden (view full) ---

164 */
165static ssize_t
166ng_MessageIn(struct physical *p, char *buf, size_t sz)
167{
168 char msgbuf[sizeof(struct ng_mesg) * 2 + NG_MSGBUFSZ];
169 struct ngdevice *dev = device2ng(p->handler);
170 struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
171 char path[NG_PATHSIZ];
146 if (data[dpos] == '%')
147 fmt[pos++] = '%';
148 fmt[pos++] = data[dpos++];
149 }
150 strcpy(fmt + pos, " %s");
151 data += dpos;
152
153 data += strspn(data, " \t");

--- 11 unchanged lines hidden (view full) ---

165 */
166static ssize_t
167ng_MessageIn(struct physical *p, char *buf, size_t sz)
168{
169 char msgbuf[sizeof(struct ng_mesg) * 2 + NG_MSGBUFSZ];
170 struct ngdevice *dev = device2ng(p->handler);
171 struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
172 char path[NG_PATHSIZ];
172 int len;
173 size_t len;
173
174#ifdef BROKEN_SELECT
175 struct timeval t;
176 fd_set *r;
177 int ret;
178
179 if (dev->cs < 0)
180 return 0;

--- 38 unchanged lines hidden (view full) ---

219static ssize_t
220ng_Write(struct physical *p, const void *v, size_t n)
221{
222 struct ngdevice *dev = device2ng(p->handler);
223
224 switch (p->dl->state) {
225 case DATALINK_DIAL:
226 case DATALINK_LOGIN:
174
175#ifdef BROKEN_SELECT
176 struct timeval t;
177 fd_set *r;
178 int ret;
179
180 if (dev->cs < 0)
181 return 0;

--- 38 unchanged lines hidden (view full) ---

220static ssize_t
221ng_Write(struct physical *p, const void *v, size_t n)
222{
223 struct ngdevice *dev = device2ng(p->handler);
224
225 switch (p->dl->state) {
226 case DATALINK_DIAL:
227 case DATALINK_LOGIN:
227 return ng_MessageOut(dev, p, v) ? n : -1;
228 return ng_MessageOut(dev, v) ? (ssize_t)n : -1;
228 }
229 }
229 return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : n;
230 return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : (ssize_t)n;
230}
231
232static ssize_t
233ng_Read(struct physical *p, void *v, size_t n)
234{
235 char hook[NG_HOOKSIZ];
236
237log_Printf(LogDEBUG, "ng_Read\n");

--- 36 unchanged lines hidden (view full) ---

274 physical_SetDescriptor(p);
275 if (dev->cs != -1)
276 close(dev->cs);
277 free(dev);
278}
279
280static void
281ng_device2iov(struct device *d, struct iovec *iov, int *niov,
231}
232
233static ssize_t
234ng_Read(struct physical *p, void *v, size_t n)
235{
236 char hook[NG_HOOKSIZ];
237
238log_Printf(LogDEBUG, "ng_Read\n");

--- 36 unchanged lines hidden (view full) ---

275 physical_SetDescriptor(p);
276 if (dev->cs != -1)
277 close(dev->cs);
278 free(dev);
279}
280
281static void
282ng_device2iov(struct device *d, struct iovec *iov, int *niov,
282 int maxiov, int *auxfd, int *nauxfd)
283 int maxiov __unused, int *auxfd, int *nauxfd)
283{
284 struct ngdevice *dev = device2ng(d);
285 int sz = physical_MaxDeviceSize();
286
287 iov[*niov].iov_base = realloc(d, sz);
288 if (iov[*niov].iov_base == NULL) {
289 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
290 AbortProgram(EX_OSERR);

--- 23 unchanged lines hidden (view full) ---

314 ng_device2iov,
315 NULL,
316 NULL,
317 NULL
318};
319
320struct device *
321ng_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
284{
285 struct ngdevice *dev = device2ng(d);
286 int sz = physical_MaxDeviceSize();
287
288 iov[*niov].iov_base = realloc(d, sz);
289 if (iov[*niov].iov_base == NULL) {
290 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
291 AbortProgram(EX_OSERR);

--- 23 unchanged lines hidden (view full) ---

315 ng_device2iov,
316 NULL,
317 NULL,
318 NULL
319};
320
321struct device *
322ng_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
322 int maxiov, int *auxfd, int *nauxfd)
323 int maxiov __unused, int *auxfd, int *nauxfd)
323{
324 if (type == NG_DEVICE) {
325 struct ngdevice *dev = (struct ngdevice *)iov[(*niov)++].iov_base;
326
327 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
328 if (dev == NULL) {
329 log_Printf(LogALERT, "Failed to allocate memory: %d\n",
330 (int)(sizeof *dev));

--- 91 unchanged lines hidden (view full) ---

422
423#define GETSEGMENT(what, from, sep, endp) \
424 getsegment(#what, (what), sizeof(what), from, sep, endp)
425
426static int
427getsegment(const char *what, char *word, size_t sz, const char *from,
428 const char *sep, const char **endp)
429{
324{
325 if (type == NG_DEVICE) {
326 struct ngdevice *dev = (struct ngdevice *)iov[(*niov)++].iov_base;
327
328 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
329 if (dev == NULL) {
330 log_Printf(LogALERT, "Failed to allocate memory: %d\n",
331 (int)(sizeof *dev));

--- 91 unchanged lines hidden (view full) ---

423
424#define GETSEGMENT(what, from, sep, endp) \
425 getsegment(#what, (what), sizeof(what), from, sep, endp)
426
427static int
428getsegment(const char *what, char *word, size_t sz, const char *from,
429 const char *sep, const char **endp)
430{
430 int len;
431 size_t len;
431
432 if ((len = strcspn(from, sep)) == 0) {
433 log_Printf(LogWARN, "%s name should not be empty !\n", what);
434 return 0;
435 }
436
437 if (len >= sz) {
438 log_Printf(LogWARN, "%s name too long, max %d !\n", what, sz - 1);

--- 24 unchanged lines hidden (view full) ---

463 struct ngm_connect ngc;
464 const char *devp, *endp;
465 char lasthook[NG_HOOKSIZ];
466 char hook[NG_HOOKSIZ];
467 char nodetype[NG_TYPESIZ + NG_NODESIZ];
468 char modname[NG_TYPESIZ + 3];
469 char path[NG_PATHSIZ];
470 char *nodename;
432
433 if ((len = strcspn(from, sep)) == 0) {
434 log_Printf(LogWARN, "%s name should not be empty !\n", what);
435 return 0;
436 }
437
438 if (len >= sz) {
439 log_Printf(LogWARN, "%s name too long, max %d !\n", what, sz - 1);

--- 24 unchanged lines hidden (view full) ---

464 struct ngm_connect ngc;
465 const char *devp, *endp;
466 char lasthook[NG_HOOKSIZ];
467 char hook[NG_HOOKSIZ];
468 char nodetype[NG_TYPESIZ + NG_NODESIZ];
469 char modname[NG_TYPESIZ + 3];
470 char path[NG_PATHSIZ];
471 char *nodename;
471 int len, sz, done, f;
472 int len, sz, done;
473 unsigned f;
472
473 dev = NULL;
474 if (p->fd < 0 && !strncasecmp(p->name.full, NETGRAPH_PREFIX,
475 sizeof NETGRAPH_PREFIX - 1)) {
476 p->fd--; /* We own the device - change fd */
477
478 if ((dev = malloc(sizeof *dev)) == NULL)
479 return NULL;

--- 262 unchanged lines hidden ---
474
475 dev = NULL;
476 if (p->fd < 0 && !strncasecmp(p->name.full, NETGRAPH_PREFIX,
477 sizeof NETGRAPH_PREFIX - 1)) {
478 p->fd--; /* We own the device - change fd */
479
480 if ((dev = malloc(sizeof *dev)) == NULL)
481 return NULL;

--- 262 unchanged lines hidden ---