diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-06 20:29:05 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-06 20:29:05 +0000 |
commit | 4f937ab6a47b65def7997fcb4e0124b0007ccb67 (patch) | |
tree | 5916f169437a1ca056a9ff36dc34b9084c2605c1 | |
parent | 27319b38759f64153abc447f73a3032f41f57f27 (diff) |
knf and other cleanups
-rw-r--r-- | usr.sbin/pppoe/client.c | 67 | ||||
-rw-r--r-- | usr.sbin/pppoe/common.c | 64 | ||||
-rw-r--r-- | usr.sbin/pppoe/pppoe.c | 26 | ||||
-rw-r--r-- | usr.sbin/pppoe/pppoe.h | 6 | ||||
-rw-r--r-- | usr.sbin/pppoe/server.c | 73 | ||||
-rw-r--r-- | usr.sbin/pppoe/session.c | 22 |
6 files changed, 53 insertions, 205 deletions
diff --git a/usr.sbin/pppoe/client.c b/usr.sbin/pppoe/client.c index 78bb91a8e51..99442e649fd 100644 --- a/usr.sbin/pppoe/client.c +++ b/usr.sbin/pppoe/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.17 2003/06/04 04:46:13 jason Exp $ */ +/* $OpenBSD: client.c,v 1.18 2004/05/06 20:29:03 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -77,10 +77,7 @@ int timer_clr(void); int timer_hit(void); int -client_mode(bfd, sysname, srvname, myea) - int bfd; - u_int8_t *sysname, *srvname; - struct ether_addr *myea; +client_mode(int bfd, u_int8_t *sysname, u_int8_t *srvname, struct ether_addr *myea) { struct ether_addr rmea; fd_set *fdsp = NULL; @@ -151,10 +148,7 @@ client_mode(bfd, sysname, srvname, myea) } static int -send_padi(fd, ea, srv) - int fd; - struct ether_addr *ea; - u_int8_t *srv; +send_padi(int fd, struct ether_addr *ea, u_int8_t *srv) { struct iovec iov[10]; struct pppoe_header ph = { @@ -210,13 +204,9 @@ send_padi(fd, ea, srv) } static int -send_padr(bfd, srv, myea, rmea, eh, ph, tl) - int bfd; - u_int8_t *srv; - struct ether_addr *myea, *rmea; - struct ether_header *eh; - struct pppoe_header *ph; - struct tag_list *tl; +send_padr(int bfd, u_int8_t *srv, struct ether_addr *myea, + struct ether_addr *rmea, struct ether_header *eh, + struct pppoe_header *ph, struct tag_list *tl) { struct iovec iov[12]; u_int16_t etype = htons(ETHERTYPE_PPPOEDISC); @@ -291,10 +281,8 @@ send_padr(bfd, srv, myea, rmea, eh, ph, tl) } static int -getpackets(bfd, srv, sysname, myea, rmea) - int bfd; - u_int8_t *srv, *sysname; - struct ether_addr *myea, *rmea; +getpackets(int bfd, u_int8_t *srv, u_int8_t *sysname, + struct ether_addr *myea, struct ether_addr *rmea) { static u_int8_t *pktbuf; u_int8_t *mpkt, *pkt, *epkt; @@ -391,14 +379,9 @@ next: static int -recv_pado(bfd, srv, myea, rmea, eh, ph, len, pkt) - int bfd; - u_int8_t *srv; - struct ether_addr *myea, *rmea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long len; - u_int8_t *pkt; +recv_pado(int bfd, u_int8_t *srv, struct ether_addr *myea, + struct ether_addr *rmea, struct ether_header *eh, + struct pppoe_header *ph, u_long len, u_int8_t *pkt) { struct tag_list tl; struct tag_node *n; @@ -455,14 +438,10 @@ out: } static int -recv_pads(bfd, srv, sysname, myea, rmea, eh, ph, len, pkt) - int bfd; - u_int8_t *srv, *sysname; - struct ether_addr *myea, *rmea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long len; - u_int8_t *pkt; +recv_pads(int bfd, u_int8_t *srv, u_int8_t *sysname, + struct ether_addr *myea, struct ether_addr *rmea, + struct ether_header *eh, struct pppoe_header *ph, + u_long len, u_int8_t *pkt) { struct tag_node *n; struct tag_list tl; @@ -510,13 +489,9 @@ out: } static int -recv_padt(bfd, myea, rmea, eh, ph, len, pkt) - int bfd; - struct ether_addr *myea, *rmea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long len; - u_int8_t *pkt; +recv_padt(int bfd, struct ether_addr *myea, struct ether_addr *rmea, + struct ether_header *eh, struct pppoe_header *ph, + u_long len, u_int8_t *pkt) { if (bcmp(&eh->ether_shost[0], rmea, ETHER_ADDR_LEN)) return (0); @@ -531,15 +506,13 @@ volatile sig_atomic_t timer_alarm; static struct sigaction timer_oact; void -timer_handler(sig) - int sig; +timer_handler(int sig) { timer_alarm = 1; } int -timer_set(sec) - u_int sec; +timer_set(u_int sec) { struct sigaction act; struct itimerval it; diff --git a/usr.sbin/pppoe/common.c b/usr.sbin/pppoe/common.c index 40287d7d62f..8e3471fa1c1 100644 --- a/usr.sbin/pppoe/common.c +++ b/usr.sbin/pppoe/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.11 2003/06/28 20:37:29 deraadt Exp $ */ +/* $OpenBSD: common.c,v 1.12 2004/05/06 20:29:04 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -52,12 +52,8 @@ #define PPP_PROG "/usr/sbin/ppp" -void debugv(char *, struct iovec *, int); - int -runppp(bpffd, sysname) - int bpffd; - u_int8_t *sysname; +runppp(int bpffd, u_int8_t *sysname) { int socks[2], fdm, fds, closeit; pid_t pid; @@ -115,10 +111,7 @@ runppp(bpffd, sysname) } int -bpf_to_ppp(pppfd, len, pkt) - int pppfd; - u_long len; - u_int8_t *pkt; +bpf_to_ppp(int pppfd, u_long len, u_int8_t *pkt) { int r; u_int8_t hdr[2] = { PPP_ALLSTATIONS, PPP_UI }; @@ -181,57 +174,6 @@ ppp_to_bpf(int bfd, int pppfd, struct ether_addr *myea, return (r == -1 && errno == ENOBUFS ? 0 : r); } -void -debugv(s, iov, cnt) - char *s; - struct iovec *iov; - int cnt; -{ - int i, j; - u_int8_t *p; - - printf("%s", s); - for (i = 0; i < cnt; i++) - for (j = 0; j < iov[i].iov_len; j++) { - p = (u_int8_t *)iov[i].iov_base; - printf("%02x:", p[j]); - } - printf("\n\n"); -} - -void -recv_debug(bpffd, ea, eh, ph, pktlen, pktbuf) - int bpffd; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; -{ - struct tag_list tl; - - printf("dst %02x:%02x:%02x:%02x:%02x:%02x, " - "src %02x:%02x:%02x:%02x:%02x:%02x, type %04x\n", - eh->ether_dhost[0], eh->ether_dhost[1], eh->ether_dhost[2], - eh->ether_dhost[3], eh->ether_dhost[4], eh->ether_dhost[5], - eh->ether_shost[0], eh->ether_shost[1], eh->ether_shost[2], - eh->ether_shost[3], eh->ether_shost[4], eh->ether_shost[5], - eh->ether_type); - printf("\tver %d, type %d, code %02x, id %04x, len %d\n", - PPPOE_VER(ph->vertype), PPPOE_TYPE(ph->vertype), - ph->code, ph->sessionid, ph->len); - - tag_init(&tl); - if (tag_pkt(&tl, pktlen, pktbuf) < 0) { - printf("bad tag pkt\n"); - goto out; - } - - tag_show(&tl); -out: - tag_destroy(&tl); -} - int send_padt(int bpffd, struct ether_addr *src_ea, struct ether_addr *dst_ea, u_int16_t id) diff --git a/usr.sbin/pppoe/pppoe.c b/usr.sbin/pppoe/pppoe.c index 315a664d47f..4882c654c74 100644 --- a/usr.sbin/pppoe/pppoe.c +++ b/usr.sbin/pppoe/pppoe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pppoe.c,v 1.12 2004/05/06 17:49:08 canacar Exp $ */ +/* $OpenBSD: pppoe.c,v 1.13 2004/05/06 20:29:04 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -65,7 +65,8 @@ int signal_init(void); void drop_privs(struct passwd *pw); int -main(int argc, char **argv) { +main(int argc, char **argv) +{ char *ifname = NULL; u_int8_t *sysname = NULL, *srvname = NULL; char ifnambuf[IFNAMSIZ]; @@ -144,10 +145,7 @@ main(int argc, char **argv) { /* bpf read filter */ int -setup_rfilter(insns, ea, server_mode) - struct bpf_insn *insns; - struct ether_addr *ea; - int server_mode; +setup_rfilter(struct bpf_insn *insns, struct ether_addr *ea, int server_mode) { u_int8_t *ep = (u_int8_t *)ea; int idx = 0; @@ -259,9 +257,7 @@ setup_rfilter(insns, ea, server_mode) /* bpf write filter */ int -setup_wfilter(insns, server_mode) - struct bpf_insn *insns; - int server_mode; +setup_wfilter(struct bpf_insn *insns, int server_mode) { int idx = 0; @@ -338,10 +334,7 @@ setup_wfilter(insns, server_mode) } int -setupfilter(ifn, ea, server_mode) - char *ifn; - struct ether_addr *ea; - int server_mode; +setupfilter(char *ifn, struct ether_addr *ea, int server_mode) { char device[sizeof "/dev/bpf0000000000"]; int fd, idx = 0; @@ -417,9 +410,7 @@ setupfilter(ifn, ea, server_mode) } int -getifhwaddr(ifnhint, ifnambuf, ea) - char *ifnhint, *ifnambuf; - struct ether_addr *ea; +getifhwaddr(char *ifnhint, char *ifnambuf, struct ether_addr *ea) { struct sockaddr_dl *dl; struct ifaddrs *ifap, *ifa; @@ -476,8 +467,7 @@ usage(void) } void -child_handler(sig) - int sig; +child_handler(int sig) { int save_errno = errno; int status; diff --git a/usr.sbin/pppoe/pppoe.h b/usr.sbin/pppoe/pppoe.h index ef1b13aa6b1..9eef41fc860 100644 --- a/usr.sbin/pppoe/pppoe.h +++ b/usr.sbin/pppoe/pppoe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pppoe.h,v 1.6 2003/06/04 04:46:13 jason Exp $ */ +/* $OpenBSD: pppoe.h,v 1.7 2004/05/06 20:29:04 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -122,18 +122,14 @@ struct pppoe_session_master { extern struct pppoe_session_master session_master; -void session_init(void); void session_destroy(struct pppoe_session *); struct pppoe_session *session_new(struct ether_addr *); struct pppoe_session *session_find_eaid(struct ether_addr *, u_int16_t); -struct pppoe_session *session_find_fd(int); int runppp(int, u_int8_t *); int bpf_to_ppp(int, u_long, u_int8_t *); int ppp_to_bpf(int, int, struct ether_addr *, struct ether_addr *, u_int16_t); int send_padt(int, struct ether_addr *, struct ether_addr *, u_int16_t); -void recv_debug(int, struct ether_addr *, - struct ether_header *, struct pppoe_header *, u_long, u_int8_t *); void debug_packet(u_int8_t *, int); u_int32_t cookie_bake(void); diff --git a/usr.sbin/pppoe/server.c b/usr.sbin/pppoe/server.c index a9be8cd02fc..87067ebcddd 100644 --- a/usr.sbin/pppoe/server.c +++ b/usr.sbin/pppoe/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.11 2003/06/28 20:37:29 deraadt Exp $ */ +/* $OpenBSD: server.c,v 1.12 2004/05/06 20:29:04 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -73,10 +73,8 @@ static u_int8_t *key_make(u_int8_t *, int, u_int8_t *, int); static int key_cmp(u_int8_t *, int, u_int8_t *, int, u_int8_t *, int); void -server_mode(bpffd, sysname, srvname, ea) - int bpffd; - u_int8_t *sysname, *srvname; - struct ether_addr *ea; +server_mode(int bpffd, u_int8_t *sysname, u_int8_t *srvname, + struct ether_addr *ea) { struct pppoe_session *ses; fd_set *fdsp = NULL; @@ -156,9 +154,7 @@ key_gen(void) } u_int8_t * -key_make(in1, in1len, in2, in2len) - u_int8_t *in1, *in2; - int in1len, in2len; +key_make(u_int8_t *in1, int in1len, u_int8_t *in2, int in2len) { u_int8_t *p; MD5_CTX ctx; @@ -175,9 +171,8 @@ key_make(in1, in1len, in2, in2len) } int -key_cmp(k, klen, in1, in1len, in2, in2len) - u_int8_t *k, *in1, *in2; - int klen, in1len, in2len; +key_cmp(u_int8_t *k, int klen, u_int8_t *in1, int in1len, + u_int8_t *in2, int in2len) { u_int8_t *p; int r; @@ -195,18 +190,15 @@ key_cmp(k, klen, in1, in1len, in2, in2len) } static void -getpackets(bpffd, sysname, ea) - int bpffd; - u_int8_t *sysname; - struct ether_addr *ea; +getpackets(int bpffd, u_int8_t *sysname, struct ether_addr *ea) { static u_int8_t *pktbuf; u_int8_t *mpkt, *pkt, *epkt; struct ether_header eh; struct pppoe_header ph; struct bpf_hdr *bh; - int rlen; u_long len; + int rlen; if (pktbuf == NULL) { pktbuf = (u_int8_t *)malloc(PPPOE_BPF_BUFSIZ); @@ -282,13 +274,8 @@ next: } static void -recv_padi(bpffd, ea, eh, ph, pktlen, pktbuf) - int bpffd; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; +recv_padi(int bpffd, struct ether_addr *ea, struct ether_header *eh, + struct pppoe_header *ph, u_long pktlen, u_int8_t *pktbuf) { struct tag_list tl; @@ -311,13 +298,8 @@ out: } static void -send_pado(bpffd, ea, eh, ph, pktlen, pktbuf) - int bpffd; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; +send_pado(int bpffd, struct ether_addr *ea, struct ether_header *eh, + struct pppoe_header *ph, u_long pktlen, u_int8_t *pktbuf) { struct pppoe_tag ktag, htag; u_int8_t hn[MAXHOSTNAMELEN]; @@ -370,14 +352,9 @@ send_pado(bpffd, ea, eh, ph, pktlen, pktbuf) } static void -recv_padr(bpffd, sysname, ea, eh, ph, pktlen, pktbuf) - int bpffd; - u_int8_t *sysname; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; +recv_padr(int bpffd, u_int8_t *sysname, struct ether_addr *ea, + struct ether_header *eh, struct pppoe_header *ph, + u_long pktlen, u_int8_t *pktbuf) { struct tag_list tl; struct tag_node *n; @@ -402,14 +379,9 @@ recv_padr(bpffd, sysname, ea, eh, ph, pktlen, pktbuf) } static void -send_pads(bpffd, sysname, ea, eh, ph, pktlen, pktbuf) - int bpffd; - u_int8_t *sysname; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; +send_pads(int bpffd, u_int8_t *sysname, struct ether_addr *ea, + struct ether_header *eh, struct pppoe_header *ph, + u_long pktlen, u_int8_t *pktbuf) { u_int8_t hn[MAXHOSTNAMELEN]; struct iovec v[16]; @@ -456,13 +428,8 @@ send_pads(bpffd, sysname, ea, eh, ph, pktlen, pktbuf) } static void -recv_padt(bpffd, ea, eh, ph, pktlen, pktbuf) - int bpffd; - struct ether_addr *ea; - struct ether_header *eh; - struct pppoe_header *ph; - u_long pktlen; - u_int8_t *pktbuf; +recv_padt(int bpffd, struct ether_addr *ea, struct ether_header *eh, + struct pppoe_header *ph, u_long pktlen, u_int8_t *pktbuf) { struct pppoe_session *s; struct tag_list tl; diff --git a/usr.sbin/pppoe/session.c b/usr.sbin/pppoe/session.c index be0998238c2..f989fd48f90 100644 --- a/usr.sbin/pppoe/session.c +++ b/usr.sbin/pppoe/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.2 2003/06/04 04:46:13 jason Exp $ */ +/* $OpenBSD: session.c,v 1.3 2004/05/06 20:29:04 deraadt Exp $ */ /* * Copyright (c) 2000 Network Security Technologies, Inc. http://www.netsec.net @@ -50,13 +50,6 @@ struct pppoe_session_master session_master; void -session_init(void) -{ - LIST_INIT(&session_master.sm_sessions); - session_master.sm_nsessions = 0; -} - -void session_destroy(struct pppoe_session *s) { if (s->s_fd != -1) @@ -118,16 +111,3 @@ session_find_eaid(struct ether_addr *ea, u_int16_t id) } return (NULL); } - -struct pppoe_session * -session_find_fd(int fd) -{ - struct pppoe_session *s; - s = LIST_FIRST(&session_master.sm_sessions); - while (s) { - if (s->s_fd == fd) - return (s); - s = LIST_NEXT(s, s_next); - } - return (NULL); -} |