patch-ipod-freebsd-4.7 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
--- conf/options	2002/10/16 20:16:10	1.1
+++ conf/options	2002/10/17 20:33:46
@@ -487,3 +487,6 @@
 
 # Polling device handling
 DEVICE_POLLING		opt_global.h
+
+# Utah testbed
+ICMP_PINGOFDEATH

--- netinet/ip_icmp.c	2002/10/16 19:36:31	1.1
+++ netinet/ip_icmp.c	2002/12/19 19:07:15
@@ -124,6 +124,11 @@
 static void	icmp_send __P((struct mbuf *, struct mbuf *, struct route *));
 static int	ip_next_mtu __P((int, int));
 
+#include "opt_icmp_pingofdeath.h"
+#ifdef ICMP_PINGOFDEATH
+static void icmp_pingofdeath __P((struct icmp *, struct ip *, int));
+#endif
+
 extern	struct protosw inetsw[];
 
 /*
@@ -570,6 +575,12 @@
 #endif
 		break;
 
+#ifdef ICMP_PINGOFDEATH
+	case ICMP_PINGOFDEATH:
+		icmp_pingofdeath(icp, ip, hlen);
+		break;
+#endif
+
 	/*
 	 * No kernel processing for the following;
 	 * just fall through to send to raw listener.
@@ -888,4 +899,99 @@
 
 #endif
 
+#ifdef ICMP_PINGOFDEATH
+#include <machine/md_var.h>
+#include <sys/syslog.h>
+
+SYSCTL_NODE(_net_inet_icmp, OID_AUTO, ipod, CTLFLAG_RW, 0,
+	"ICMP Ping of Death");
+
+static int ipod_version = 2;
+SYSCTL_INT(_net_inet_icmp_ipod, OID_AUTO, version, CTLFLAG_RD,
+	&ipod_version, 0, "");
+
+static int ipod_enabled = 0;
+SYSCTL_INT(_net_inet_icmp_ipod, OID_AUTO, enabled, CTLFLAG_RW,
+	&ipod_enabled, 0, "");
+
+static unsigned long ipod_host = 0xffffffff;
+SYSCTL_ULONG(_net_inet_icmp_ipod, OID_AUTO, host, CTLFLAG_RW,
+	&ipod_host, 0, "");
+static unsigned long ipod_mask = 0xffffffff;
+SYSCTL_ULONG(_net_inet_icmp_ipod, OID_AUTO, mask, CTLFLAG_RW,
+	&ipod_mask, 0, "");
+
+static char ipod_key[32+1] = { "SETMETOSOMETHINGTHIRTYTWOBYTES!!" };
+#define IPOD_CHECK_KEY \
+	(ipod_key[0] != 0)
+#define IPOD_VALID_KEY(d) \
+	(strncmp(ipod_key, (char *)(d), strlen(ipod_key)) == 0)
+
+static int
+ipod_getkey(SYSCTL_HANDLER_ARGS)
+{
+	int error;
+
+	/* XXX fake up a result */
+	error = SYSCTL_OUT(req, "XXXX", 4+1);
+	if (error || !req->newptr)
+		return (error);
+
+	if ((req->newlen - req->newidx) >= sizeof(ipod_key))
+		return (EINVAL);
+
+	arg2 = (req->newlen - req->newidx);
+	error = SYSCTL_IN(req, ipod_key, arg2);
+	memset(&ipod_key[arg2], 0, sizeof(ipod_key) - arg2);
+
+	return (error);
+}
+
+SYSCTL_PROC(_net_inet_icmp_ipod, OID_AUTO, key, CTLTYPE_STRING | CTLFLAG_RW,
+	NULL, 0, ipod_getkey, "A", "");
+
+static void
+icmp_pingofdeath(icp, ip, hlen)
+	struct icmp *icp;
+	struct ip *ip;
+	int hlen;
+{
+	int doit = 0;
 
+	/*
+	 * If IPOD not enabled or wrong ICMP code, ignore.
+	 */
+	if (!ipod_enabled || icp->icmp_code != 6)
+		return;
+
+	/*
+	 * First check the source address info.
+	 * If host not set, ignore.
+	 */
+	if (ipod_host != 0xffffffff &&
+	    (ntohl(ip->ip_src.s_addr) & ipod_mask) == ipod_host) {
+		/*
+		 * Now check the key if enabled.
+		 * If packet doesn't contain enough data or key
+		 * is otherwise invalid, ignore.
+		 */
+		if (IPOD_CHECK_KEY) {
+			if (ip->ip_len >= strlen(ipod_key) &&
+			    IPOD_VALID_KEY(icp->icmp_data))
+				doit = 1;
+		} else {
+			doit = 1;
+		}
+	}
+
+	if (doit) {
+		ipod_enabled = 0;
+		printf("IPOD: reboot forced by %lx...\n",
+		       ntohl(ip->ip_src.s_addr));
+		cpu_reset();
+	} else {
+		log(LOG_ERR, "IPOD: from %lx rejected\n",
+		    ntohl(ip->ip_src.s_addr));
+	}
+}
+#endif