-/* $OpenBSD: ofp10.c,v 1.4 2016/07/21 07:58:44 reyk Exp $ */
+/* $OpenBSD: ofp10.c,v 1.5 2016/07/21 08:39:23 reyk Exp $ */
/*
* Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org>
len = ntohs(pin->pin_total_len);
srcport = ntohs(pin->pin_port);
- if ((dstport = packet_input(sc, con->con_switch,
- srcport, ibuf, len, &pkt)) == -1 ||
+ if (packet_input(sc, con->con_switch,
+ srcport, &dstport, ibuf, len, &pkt) == -1 ||
dstport > OFP10_PORT_MAX) {
/* fallback to flooding */
dstport = OFP10_PORT_FLOOD;
-/* $OpenBSD: packet.c,v 1.2 2016/07/20 20:07:02 reyk Exp $ */
+/* $OpenBSD: packet.c,v 1.3 2016/07/21 08:39:23 reyk Exp $ */
/*
* Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org>
return (0);
}
-uint32_t
-packet_input(struct switchd *sc, struct switch_control *sw, uint32_t port,
- struct ibuf *ibuf, size_t len, struct packet *pkt)
+int
+packet_input(struct switchd *sc, struct switch_control *sw, uint32_t srcport,
+ uint32_t *dstport, struct ibuf *ibuf, size_t len, struct packet *pkt)
{
struct ether_header *eh;
struct macaddr *src, *dst;
len -= sizeof(*eh);
if ((packet_ether_unicast(eh->ether_shost) == -1) ||
- (src = switch_learn(sc, sw, eh->ether_shost, port)) == NULL)
+ (src = switch_learn(sc, sw, eh->ether_shost, srcport)) == NULL)
return (-1);
if (packet_ether_unicast(eh->ether_dhost) == -1)
src->mac_port,
dst == NULL ? OFP_PORT_ANY : dst->mac_port);
- return (dst == NULL ? OFP_PORT_ANY : dst->mac_port);
+ if (dstport)
+ *dstport = dst == NULL ? OFP_PORT_ANY : dst->mac_port;
+
+ return (0);
}
-/* $OpenBSD: switchd.h,v 1.6 2016/07/21 07:58:44 reyk Exp $ */
+/* $OpenBSD: switchd.h,v 1.7 2016/07/21 08:39:23 reyk Exp $ */
/*
* Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org>
int switchd_open_device(struct privsep *, const char *, size_t);
/* packet.c */
-uint32_t packet_input(struct switchd *, struct switch_control *,
- uint32_t, struct ibuf *, size_t, struct packet *);
+int packet_input(struct switchd *, struct switch_control *,
+ uint32_t, uint32_t *, struct ibuf *, size_t,
+ struct packet *);
/* switch.c */
void switch_init(struct switchd *);