summaryrefslogtreecommitdiff
path: root/common/lpf.c
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>2000-07-27 09:03:08 +0000
committerTed Lemon <source@isc.org>2000-07-27 09:03:08 +0000
commit6ceb9118e9b730eb4aebf3bfe9e5bb2c3daa091e (patch)
tree71a9b3f5b41acb52efb92836608b44ee2a963588 /common/lpf.c
parenta8c190df765a1f47009dc384eec2534606722e9f (diff)
downloadisc-dhcp-6ceb9118e9b730eb4aebf3bfe9e5bb2c3daa091e.tar.gz
Reference count binding scopes. Align IP headers on output.
Diffstat (limited to 'common/lpf.c')
-rw-r--r--common/lpf.c85
1 files changed, 52 insertions, 33 deletions
diff --git a/common/lpf.c b/common/lpf.c
index bdbc0754..21a2fa93 100644
--- a/common/lpf.c
+++ b/common/lpf.c
@@ -37,7 +37,7 @@
#ifndef lint
static char copyright[] =
-"$Id: lpf.c,v 1.25 2000/06/08 21:14:14 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
+"$Id: lpf.c,v 1.26 2000/07/27 09:02:33 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -83,14 +83,18 @@ int if_register_lpf (info)
struct sockaddr sa;
/* Make an LPF socket. */
- if ((sock = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
+ if ((sock = socket(PF_PACKET, SOCK_PACKET,
+ htons((short)ETH_P_ALL))) < 0) {
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
- errno == EAFNOSUPPORT || errno == EINVAL)
- log_fatal ("socket: %m - make sure %s %s %s!",
- "CONFIG_PACKET (Packet socket)"
- "and CONFIG_FILTER (Socket Filtering) are",
- "enabled in your kernel configuration");
+ errno == EAFNOSUPPORT || errno == EINVAL) {
+ log_error ("socket: %m - make sure");
+ log_error ("CONFIG_PACKET (Packet socket) %s",
+ "and CONFIG_FILTER");
+ log_error ("(Socket Filtering) are enabled %s",
+ "in your kernel");
+ log_fatal ("configuration!");
+ }
log_fatal ("Open a socket for LPF: %m");
}
@@ -101,11 +105,14 @@ int if_register_lpf (info)
if (bind (sock, &sa, sizeof sa)) {
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
- errno == EAFNOSUPPORT || errno == EINVAL)
- log_fatal ("socket: %m - make sure %s %s %s!",
- "CONFIG_PACKET (Packet socket)"
- "and CONFIG_FILTER (Socket Filtering) are",
- "enabled in your kernel configuration");
+ errno == EAFNOSUPPORT || errno == EINVAL) {
+ log_error ("socket: %m - make sure");
+ log_error ("CONFIG_PACKET (Packet socket) %s",
+ "and CONFIG_FILTER");
+ log_error ("(Socket Filtering) are enabled %s",
+ "in your kernel");
+ log_fatal ("configuration!");
+ }
log_fatal ("Bind socket to interface: %m");
}
@@ -222,17 +229,20 @@ static void lpf_gen_filter_setup (info)
/* Patch the server port into the LPF program...
XXX changes to filter program may require changes
to the insn number(s) used below! XXX */
- dhcp_bpf_filter [8].k = ntohs (local_port);
+ dhcp_bpf_filter [8].k = ntohs ((short)local_port);
if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
sizeof p) < 0) {
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
- errno == EAFNOSUPPORT)
- log_fatal ("socket: %m - make sure %s %s %s!",
- "CONFIG_PACKET (Packet socket)"
- "and CONFIG_FILTER (Socket Filtering) are",
- "enabled in your kernel configuration");
+ errno == EAFNOSUPPORT) {
+ log_error ("socket: %m - make sure");
+ log_error ("CONFIG_PACKET (Packet socket) %s",
+ "and CONFIG_FILTER");
+ log_error ("(Socket Filtering) are enabled %s",
+ "in your kernel");
+ log_fatal ("configuration!");
+ }
log_fatal ("Can't install packet filter program: %m");
}
}
@@ -258,11 +268,14 @@ static void lpf_tr_filter_setup (info)
sizeof p) < 0) {
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
- errno == EAFNOSUPPORT)
- log_fatal ("socket: %m - make sure %s %s %s!",
- "CONFIG_PACKET (Packet socket)"
- "and CONFIG_FILTER (Socket Filtering) are",
- "enabled in your kernel configuration");
+ errno == EAFNOSUPPORT) {
+ log_error ("socket: %m - make sure");
+ log_error ("CONFIG_PACKET (Packet socket) %s",
+ "and CONFIG_FILTER");
+ log_error ("(Socket Filtering) are enabled %s",
+ "in your kernel");
+ log_fatal ("configuration!");
+ }
log_fatal ("Can't install packet filter program: %m");
}
}
@@ -278,21 +291,27 @@ ssize_t send_packet (interface, packet, raw, len, from, to, hto)
struct sockaddr_in *to;
struct hardware *hto;
{
- unsigned bufp = 0;
- unsigned char buf [1500];
+ unsigned hbufp = 0, ibufp = 0;
+ double hh [16];
+ double ih [1536 / sizeof (double)];
+ unsigned char *buf = (unsigned char *)ih;
struct sockaddr sa;
int result;
+ int fudge;
if (!strcmp (interface -> name, "fallback"))
return send_fallback (interface, packet, raw,
len, from, to, hto);
/* Assemble the headers... */
- assemble_hw_header (interface, buf, &bufp, hto);
- assemble_udp_ip_header (interface, buf, &bufp, from.s_addr,
+ assemble_hw_header (interface, (unsigned char *)hh, &hbufp, hto);
+ fudge = hbufp % 4; /* IP header must be word-aligned. */
+ memcpy (buf + fudge, (unsigned char *)hh, hbufp);
+ ibufp = hbufp + fudge;
+ assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
to -> sin_addr.s_addr, to -> sin_port,
(unsigned char *)raw, len);
- memcpy (buf + bufp, raw, len);
+ memcpy (buf + ibufp, raw, len);
/* For some reason, SOCK_PACKET sockets can't be connected,
so we have to do a sentdo every time. */
@@ -301,8 +320,8 @@ ssize_t send_packet (interface, packet, raw, len, from, to, hto)
strncpy (sa.sa_data,
(const char *)interface -> ifp, sizeof sa.sa_data);
- result = sendto (interface -> wfdesc, buf, bufp + len, 0,
- &sa, sizeof sa);
+ result = sendto (interface -> wfdesc,
+ buf + fudge, ibufp + len - fudge, 0, &sa, sizeof sa);
if (result < 0)
log_error ("send_packet: %m");
return result;
@@ -321,7 +340,7 @@ ssize_t receive_packet (interface, buf, len, from, hfrom)
int length = 0;
int offset = 0;
unsigned char ibuf [1500];
- int bufix = 0;
+ unsigned bufix = 0;
length = read (interface -> rfdesc, ibuf, sizeof ibuf);
if (length <= 0)
@@ -342,8 +361,8 @@ ssize_t receive_packet (interface, buf, len, from, hfrom)
length -= offset;
/* Decode the IP and UDP headers... */
- offset = decode_udp_ip_header (interface, ibuf, bufix,
- from, (unsigned char *)0, length);
+ offset = decode_udp_ip_header (interface, ibuf, bufix, from,
+ (unsigned char *)0, (unsigned)length);
/* If the IP or UDP checksum was bad, skip the packet... */
if (offset < 0)