summaryrefslogtreecommitdiffstats
path: root/usr.sbin/switchd/ofp10.c
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2016-10-05 15:42:28 +0000
committerreyk <reyk@openbsd.org>2016-10-05 15:42:28 +0000
commit625d31033fc44dc4373b9f95318a022221125175 (patch)
tree76408d229e0dd94943c1ad77a651374ad59483ba /usr.sbin/switchd/ofp10.c
parentBump the sizes of generated jumbo frames up to the max. (diff)
downloadwireguard-openbsd-625d31033fc44dc4373b9f95318a022221125175.tar.xz
wireguard-openbsd-625d31033fc44dc4373b9f95318a022221125175.zip
Move ofp_validate_header() to ofp10.c until we have a better place
Diffstat (limited to 'usr.sbin/switchd/ofp10.c')
-rw-r--r--usr.sbin/switchd/ofp10.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/usr.sbin/switchd/ofp10.c b/usr.sbin/switchd/ofp10.c
index b002c37f7eb..205f7b0a184 100644
--- a/usr.sbin/switchd/ofp10.c
+++ b/usr.sbin/switchd/ofp10.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofp10.c,v 1.11 2016/09/30 12:48:27 reyk Exp $ */
+/* $OpenBSD: ofp10.c,v 1.12 2016/10/05 15:42:28 reyk Exp $ */
/*
* Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org>
@@ -85,6 +85,40 @@ struct ofp_callback ofp10_callbacks[] = {
};
int
+ofp_validate_header(struct switchd *sc,
+ struct sockaddr_storage *src, struct sockaddr_storage *dst,
+ struct ofp_header *oh, uint8_t version)
+{
+ struct constmap *tmap;
+
+ /* For debug, don't verify the header if the version is unset */
+ if (version != OFP_V_0 &&
+ (oh->oh_version != version ||
+ oh->oh_type >= OFP_T_TYPE_MAX))
+ return (-1);
+
+ switch (version) {
+ case OFP_V_1_0:
+ case OFP_V_1_1:
+ tmap = ofp10_t_map;
+ break;
+ case OFP_V_1_3:
+ default:
+ tmap = ofp_t_map;
+ break;
+ }
+
+ log_debug("%s > %s: version %s type %s length %u xid %u",
+ print_host(src, NULL, 0),
+ print_host(dst, NULL, 0),
+ print_map(oh->oh_version, ofp_v_map),
+ print_map(oh->oh_type, tmap),
+ ntohs(oh->oh_length), ntohl(oh->oh_xid));
+
+ return (0);
+}
+
+int
ofp10_validate(struct switchd *sc,
struct sockaddr_storage *src, struct sockaddr_storage *dst,
struct ofp_header *oh, struct ibuf *ibuf)