POKE_RESTORE(pos_checksum);
if (!(POKE_UINT16(ntohs(checksum)))) goto toobig;
- if (hardware->h_ops->send(global, hardware,
+ if (interfaces_send_helper(global, hardware,
(char *)packet, end - packet) == -1) {
log_warn("cdp", "unable to send packet on real device for %s",
hardware->h_ifname);
checksum = frame_checksum(pos_edp, v, 0);
if (!(POKE_UINT16(ntohs(checksum)))) goto toobig;
- if (hardware->h_ops->send(global, hardware,
+ if (interfaces_send_helper(global, hardware,
(char *)packet, end - packet) == -1) {
log_warn("edp", "unable to send packet on real device for %s",
hardware->h_ifname);
return 0;
}
-static int
-iface_bond_send(struct lldpd *cfg, struct lldpd_hardware *hardware,
- char *buffer, size_t size)
-{
- log_debug("interfaces", "send PDU to bonded device %s",
- hardware->h_ifname);
- if (size < 2 * ETHER_ADDR_LEN) {
- log_warnx("interfaces",
- "packet to send on %s is too small!",
- hardware->h_ifname);
- return 0;
- }
- interfaces_helper_mangle_mac(cfg, buffer + ETHER_ADDR_LEN);
- return write(hardware->h_sendfd,
- buffer, size);
-}
-
static int
iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware,
int fd, char *buffer, size_t size)
}
struct lldpd_ops bond_ops = {
- .send = iface_bond_send,
+ .send = iflinux_eth_send,
.recv = iface_bond_recv,
.cleanup = iface_bond_close,
};
continue;
}
hardware->h_ops = &bond_ops;
+ hardware->h_mangle = 1;
TAILQ_INSERT_TAIL(&cfg->g_hardware, hardware, h_entries);
} else {
if (hardware->h_flags) continue; /* Already seen this time */
}
/**
- * Mangle the MAC address to avoid duplicates.
+ * Send the packet using the hardware function. Optionnaly mangle the MAC address.
*
* With bonds, we have duplicate MAC address on different physical
- * interfaces. We need to alter the source MAC address when we send on
- * an inactive slave. We try to set "local" bit to 1 first. If it is
- * already set to 1, use an unused MAC address instead.
+ * interfaces. We need to alter the source MAC address when we send on an
+ * inactive slave. The `h_mangle` flah is used to know if we need to do
+ * something like that.
*/
-void
-interfaces_helper_mangle_mac(struct lldpd *cfg, char *src_mac)
+int
+interfaces_send_helper(struct lldpd *cfg,
+ struct lldpd_hardware *hardware,
+ char *buffer, size_t size)
{
+ if (size < 2 * ETHER_ADDR_LEN) {
+ log_warnx("interfaces",
+ "packet to send on %s is too small!",
+ hardware->h_ifname);
+ return 0;
+ }
+ if (hardware->h_mangle) {
#define MAC_UL_ADMINISTERED_BIT_MASK 0x02
- char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef};
-
- switch (cfg->g_config.c_bond_slave_src_mac_type) {
- case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED:
- if (*src_mac & MAC_UL_ADMINISTERED_BIT_MASK) {
- /* If locally administered bit already set,
- * use zero mac
- */
+ char *src_mac = buffer + ETHER_ADDR_LEN;
+ char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef};
+
+ switch (cfg->g_config.c_bond_slave_src_mac_type) {
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED:
+ if (*src_mac & MAC_UL_ADMINISTERED_BIT_MASK) {
+ /* If locally administered bit already set,
+ * use zero mac
+ */
+ memset(src_mac, 0, ETHER_ADDR_LEN);
+ break;
+ }
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED:
+ memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
+ break;
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO:
memset(src_mac, 0, ETHER_ADDR_LEN);
- return;
+ break;
}
- case LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED:
- memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
- return;
- case LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO:
- memset(src_mac, 0, ETHER_ADDR_LEN);
- return;
}
+ return hardware->h_ops->send(cfg, hardware, buffer, size);
}
POKE_END_LLDP_TLV))
goto toobig;
- if (hardware->h_ops->send(global, hardware,
+ if (interfaces_send_helper(global, hardware,
(char *)packet, pos - packet) == -1) {
log_warn("lldp", "unable to send packet on real device for %s",
hardware->h_ifname);
void interfaces_helper_vlan(struct lldpd *,
struct interfaces_device_list *);
#endif
-void interfaces_helper_mangle_mac(struct lldpd *, char *);
+int interfaces_send_helper(struct lldpd *,
+ struct lldpd_hardware *, char *, size_t);
void interfaces_setup_multicast(struct lldpd *, const char *, int);
int interfaces_routing_enabled(struct lldpd *);
POKE_SAVE(end)))
goto toobig;
- if (hardware->h_ops->send(global, hardware,
+ if (interfaces_send_helper(global, hardware,
(char *)packet, end - packet) == -1) {
log_warn("sonmp", "unable to send packet on real device for %s",
hardware->h_ifname);
PEEK_DISCARD(ETHER_ADDR_LEN - 1); /* Modify the last byte of the MAC address */
(void)POKE_UINT8(1);
- if (hardware->h_ops->send(global, hardware,
+ if (interfaces_send_helper(global, hardware,
(char *)packet, end - packet) == -1) {
log_warn("sonmp", "unable to send second SONMP packet on real device for %s",
hardware->h_ifname);
struct lldpd *h_cfg; /* Pointer to main configuration */
void *h_recv; /* FD for reception */
int h_sendfd; /* FD for sending, only used by h_ops */
+ int h_mangle; /* 1 if we have to mangle the MAC address */
struct lldpd_ops *h_ops; /* Hardware-dependent functions */
void *h_data; /* Hardware-dependent data */
void *h_timer; /* Timer for this port */