Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Created February 3, 2009 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheldonh/57421 to your computer and use it in GitHub Desktop.
Save sheldonh/57421 to your computer and use it in GitHub Desktop.
12-bit vhid support for FreeBSD CARP
Index: sys/netinet/ip_carp.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_carp.c,v
retrieving revision 1.52.2.2.2.1
diff -u -d -r1.52.2.2.2.1 ip_carp.c
--- sys/netinet/ip_carp.c 25 Nov 2008 02:59:29 -0000 1.52.2.2.2.1
+++ sys/netinet/ip_carp.c 18 Feb 2009 11:09:32 -0000
@@ -239,7 +239,7 @@
carp_hmac_prepare(struct carp_softc *sc)
{
u_int8_t version = CARP_VERSION, type = CARP_ADVERTISEMENT;
- u_int8_t vhid = sc->sc_vhid & 0xff;
+ u_int16_t vhid = sc->sc_vhid & 0x0fff;
struct ifaddr *ifa;
int i, found;
#ifdef INET
@@ -909,7 +909,6 @@
ch.carp_advbase = advbase;
ch.carp_advskew = advskew;
ch.carp_authlen = 7; /* XXX DEFINE */
- ch.carp_pad1 = 0; /* must be zero */
ch.carp_cksum = 0;
#ifdef INET
@@ -1935,7 +1934,7 @@
}
}
if (carpr.carpr_vhid > 0) {
- if (carpr.carpr_vhid > 255) {
+ if (carpr.carpr_vhid > CARP_MAX_VHID) {
error = EINVAL;
break;
}
@@ -1956,8 +1955,8 @@
IF_LLADDR(sc->sc_ifp)[1] = 0;
IF_LLADDR(sc->sc_ifp)[2] = 0x5e;
IF_LLADDR(sc->sc_ifp)[3] = 0;
- IF_LLADDR(sc->sc_ifp)[4] = 1;
- IF_LLADDR(sc->sc_ifp)[5] = sc->sc_vhid;
+ IF_LLADDR(sc->sc_ifp)[4] = (sc->sc_vhid & 0x0f00) >> 8;
+ IF_LLADDR(sc->sc_ifp)[5] = (sc->sc_vhid & 0x00ff);
error--;
}
if (carpr.carpr_advbase > 0 || carpr.carpr_advskew > 0) {
@@ -2103,10 +2102,11 @@
eh->ether_shost[1] = 0;
eh->ether_shost[2] = 0x5e;
eh->ether_shost[3] = 0;
- eh->ether_shost[4] = 1;
- eh->ether_shost[5] = sc->sc_vhid;
+ eh->ether_shost[4] = (sc->sc_vhid & 0x0f00) >> 8;
+ eh->ether_shost[5] = (sc->sc_vhid & 0x00ff);
}
break;
+#if 0 /* XXX rather disable than run untested code */
case IFT_FDDI: {
struct fddi_header *fh;
@@ -2130,6 +2130,7 @@
th->iso88025_shost[5] = 0;
}
break;
+#endif
default:
printf("%s: carp is not supported for this interface type\n",
ifp->if_xname);
Index: sys/netinet/ip_carp.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_carp.h,v
retrieving revision 1.3.6.1
diff -u -d -r1.3.6.1 ip_carp.h
--- sys/netinet/ip_carp.h 25 Nov 2008 02:59:29 -0000 1.3.6.1
+++ sys/netinet/ip_carp.h 18 Feb 2009 11:12:17 -0000
@@ -36,9 +36,9 @@
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * |Version| Type | VirtualHostID | AdvSkew | Auth Len |
+ * |Version| Type | VirtualHostID | Rsrvd | AdvSkew |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | Reserved | AdvBase | Checksum |
+ * | Auth Len | AdvBase | Checksum |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Counter (1) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -66,10 +66,9 @@
u_int8_t carp_version:4,
carp_type:4;
#endif
- u_int8_t carp_vhid; /* virtual host id */
+ u_int16_t carp_vhid; /* virtual host id */
u_int8_t carp_advskew; /* advertisement skew */
u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */
- u_int8_t carp_pad1; /* reserved */
u_int8_t carp_advbase; /* advertisement interval */
u_int16_t carp_cksum;
u_int32_t carp_counter[2];
@@ -83,7 +82,7 @@
#define CARP_DFLTTL 255
/* carp_version */
-#define CARP_VERSION 2
+#define CARP_VERSION 3
/* carp_type */
#define CARP_ADVERTISEMENT 0x01
@@ -93,6 +92,8 @@
/* carp_advbase */
#define CARP_DFLTINTV 1
+#define CARP_MAX_VHID 4094
+
/*
* Statistics.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment