diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2004-04-20 20:56:48 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2004-04-20 20:56:48 +0000 |
commit | e69f4ae27be5c5fe034e01d855e2927ae86deb9f (patch) | |
tree | 12213e3ce7eaaf7efa905f1dd178776a4c81e64a /usr.sbin/dhcrelay | |
parent | ff28a27bf348e5011bb77cc21eec7b0504fc7902 (diff) |
get rid of the -p switch, use fixed values for server and client ports,
rename port variables for clarity.
ok henning@
Diffstat (limited to 'usr.sbin/dhcrelay')
-rw-r--r-- | usr.sbin/dhcrelay/bpf.c | 16 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/dhcpd.h | 9 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/dhcrelay.c | 31 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/packet.c | 17 |
4 files changed, 24 insertions, 49 deletions
diff --git a/usr.sbin/dhcrelay/bpf.c b/usr.sbin/dhcrelay/bpf.c index 7359d94119c..4c50976cdd0 100644 --- a/usr.sbin/dhcrelay/bpf.c +++ b/usr.sbin/dhcrelay/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.2 2004/04/20 04:19:00 deraadt Exp $ */ +/* $OpenBSD: bpf.c,v 1.3 2004/04/20 20:56:47 canacar Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -95,10 +95,7 @@ if_register_send(struct interface_info *info) } /* - * Packet filter program... - * - * XXX: Changes to the filter program may require changes to the - * constant offsets used in if_register_send to patch the BPF program! + * Packet filter program: 'ip and udp and dst port SERVER_PORT' */ struct bpf_insn dhcp_bpf_filter[] = { /* Make sure this is an IP packet... */ @@ -118,7 +115,7 @@ struct bpf_insn dhcp_bpf_filter[] = { /* Make sure it's to the right port... */ BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1), /* patch */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, SERVER_PORT, 0, 1), /* If we passed all the tests, ask for the whole packet. */ BPF_STMT(BPF_RET+BPF_K, (u_int)-1), @@ -170,13 +167,6 @@ if_register_receive(struct interface_info *info) p.bf_len = dhcp_bpf_filter_len; p.bf_insns = dhcp_bpf_filter; - /* Patch the server port into the BPF program... - * - * XXX: changes to filter program may require changes to the - * insn number(s) used below! - */ - dhcp_bpf_filter[8].k = LOCAL_PORT; - if (ioctl(info->rfdesc, BIOCSETF, &p) < 0) error("Can't install packet filter program: %m"); } diff --git a/usr.sbin/dhcrelay/dhcpd.h b/usr.sbin/dhcrelay/dhcpd.h index 914c902fd75..b4c1b0e6284 100644 --- a/usr.sbin/dhcrelay/dhcpd.h +++ b/usr.sbin/dhcrelay/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.4 2004/04/20 04:19:00 deraadt Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.5 2004/04/20 20:56:47 canacar Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -73,8 +73,8 @@ #include "dhcp.h" -#define LOCAL_PORT 68 -#define REMOTE_PORT 67 +#define SERVER_PORT 67 +#define CLIENT_PORT 68 struct iaddr { int len; @@ -178,6 +178,9 @@ ssize_t decode_hw_header(struct interface_info *, unsigned char *, ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, int, struct sockaddr_in *, unsigned char *, int); +/* dhcrelay.c */ +extern u_int16_t server_port; +extern u_int16_t client_port; /* crap */ extern time_t cur_time; diff --git a/usr.sbin/dhcrelay/dhcrelay.c b/usr.sbin/dhcrelay/dhcrelay.c index 30f53dc5ee0..ea2cfa42e5c 100644 --- a/usr.sbin/dhcrelay/dhcrelay.c +++ b/usr.sbin/dhcrelay/dhcrelay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcrelay.c,v 1.16 2004/04/20 04:19:00 deraadt Exp $ */ +/* $OpenBSD: dhcrelay.c,v 1.17 2004/04/20 20:56:47 canacar Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org> @@ -52,8 +52,8 @@ time_t max_lease_time = 86400; /* 24 hours... */ int log_perror = 1; -u_int16_t local_port; -u_int16_t remote_port; +u_int16_t server_port; +u_int16_t client_port; int log_priority; struct interface_info *interfaces = NULL; @@ -67,7 +67,6 @@ main(int argc, char *argv[]) { int ch, no_daemon = 0; extern char *__progname; - struct servent *ent; struct server_list *sp = NULL; struct passwd *pw; @@ -75,7 +74,7 @@ main(int argc, char *argv[]) openlog(__progname, LOG_NDELAY, DHCPD_LOG_FACILITY); setlogmask(LOG_UPTO(LOG_INFO)); - while ((ch = getopt(argc, argv, "di:p:")) != -1) { + while ((ch = getopt(argc, argv, "di:")) != -1) { switch (ch) { case 'd': no_daemon = 1; @@ -89,9 +88,6 @@ main(int argc, char *argv[]) strlcpy(interfaces->name, optarg, sizeof(interfaces->name)); break; - case 'p': - local_port = htons(atoi(optarg)); - break; default: usage(); /* not reached */ @@ -133,16 +129,9 @@ main(int argc, char *argv[]) if (interfaces == NULL) error("no interface given"); - /* Default to the DHCP/BOOTP port. */ - if (!local_port) { - ent = getservbyname("dhcps", "udp"); - if (!ent) - local_port = htons(67); - else - local_port = ent->s_port; - endservent(); - } - remote_port = htons(ntohs(local_port) + 1); + /* Default DHCP/BOOTP ports. */ + server_port = htons(SERVER_PORT); + client_port = htons(CLIENT_PORT); /* We need at least one server. */ if (!sp) @@ -150,7 +139,7 @@ main(int argc, char *argv[]) /* Set up the server sockaddrs. */ for (sp = servers; sp; sp = sp->next) { - sp->to.sin_port = local_port; + sp->to.sin_port = server_port; sp->to.sin_family = AF_INET; sp->to.sin_len = sizeof sp->to; } @@ -197,10 +186,10 @@ relay(struct interface_info *ip, struct dhcp_packet *packet, int length, bzero(&to, sizeof(to)); if (!(packet->flags & htons(BOOTP_BROADCAST))) { to.sin_addr = packet->yiaddr; - to.sin_port = remote_port; + to.sin_port = client_port; } else { to.sin_addr.s_addr = htonl(INADDR_BROADCAST); - to.sin_port = remote_port; + to.sin_port = client_port; } to.sin_family = AF_INET; to.sin_len = sizeof to; diff --git a/usr.sbin/dhcrelay/packet.c b/usr.sbin/dhcrelay/packet.c index 925b3afe36a..7ba4acb6649 100644 --- a/usr.sbin/dhcrelay/packet.c +++ b/usr.sbin/dhcrelay/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.1 2004/04/12 21:10:28 henning Exp $ */ +/* $OpenBSD: packet.c,v 1.2 2004/04/20 20:56:47 canacar Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -52,11 +52,6 @@ u_int32_t checksum(unsigned char *, unsigned, u_int32_t); u_int32_t wrapsum(u_int32_t); -void assemble_ethernet_header(struct interface_info *, unsigned char *, - int *, struct hardware *); -ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, - int bufix, struct hardware *); - u_int32_t checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum) { @@ -100,11 +95,9 @@ assemble_hw_header(struct interface_info *interface, unsigned char *buf, memcpy(eh.ether_dhost, to->haddr, sizeof(eh.ether_dhost)); else memset(eh.ether_dhost, 0xff, sizeof(eh.ether_dhost)); - if (interface->hw_address.hlen == sizeof(eh.ether_shost)) - memcpy(eh.ether_shost, interface->hw_address.haddr, - sizeof(eh.ether_shost)); - else - memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost)); + + /* source address is filled in by the kernel */ + memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost)); eh.ether_type = htons(ETHERTYPE_IP); @@ -136,7 +129,7 @@ assemble_udp_ip_header(struct interface_info *interface, unsigned char *buf, memcpy(&buf[*bufix], &ip, sizeof(ip)); *bufix += sizeof(ip); - udp.uh_sport = htons(LOCAL_PORT); /* XXX */ + udp.uh_sport = server_port; /* XXX */ udp.uh_dport = port; /* XXX */ udp.uh_ulen = htons(sizeof(udp) + len); memset(&udp.uh_sum, 0, sizeof(udp.uh_sum)); |