diff -aburN --exclude=.svn vrrpd-1.0/debian/dirs vrrpd-1.0-patched/debian/dirs
--- vrrpd-1.0/debian/dirs	2009-03-16 23:18:04.417426353 +0100
+++ vrrpd-1.0-patched/debian/dirs	2009-03-16 23:17:58.389405898 +0100
@@ -1,2 +1,2 @@
 usr/sbin/
-var/run/vrrpd/lock
+var/vrrp/
diff -aburN --exclude=.svn vrrpd-1.0/debian/vrrp_switch vrrpd-1.0-patched/debian/vrrp_switch
--- vrrpd-1.0/debian/vrrp_switch	2004-12-05 20:16:33.000000000 +0100
+++ vrrpd-1.0-patched/debian/vrrp_switch	2009-03-16 17:35:10.289405572 +0100
@@ -1,9 +1,16 @@
-#!/bin/bash
+#!/bin/sh
 # @(#)$Id: vrrp_switch,v 1.1 2003/10/03 13:33:23 plg Exp $
 # This script is called when VRRP states switches
 # Arguments to the script:
 # $1 = master / slave (new state)
 # $2 = VRID concerned
+# Todo
+# $3 = VRRP_IP
+# $4 = ROUTER_IF
+# $5 = Instance name
+# $6 = Priority
+# $7 = adv
+# $8 = preempt
 #
 # you can reload services that need the IP address to be configured
 # when they initialise,  ....
@@ -13,15 +20,99 @@
 # RedHat:
 # STATEFILE="/var/lib/vrrpd/state"
 # Debian:
-STATEFILE="/var/run/vrrpd/state"
+STATEFILE="/var/vrrp/state"
+EBTABLES="/sbin/ebtables"
+
+# VARs
+
+STATE=$1
+VRRP_ID=$2
+VRRP_IP=$3
+ROUTER_IF=`echo $4 | awk -F ":" '{print $1}'`
+ROUTER_MAC=`ifconfig $ROUTER_IF | grep HWaddr | awk -F "HWaddr " '{print $2}'`
+VRRP_MAC="00:00:5E:00:01:`printf "%x" $VRRP_ID`"
+VRRP_NAME=$5
+VRRP_PRIO=$6
+VRRP_ADV=$7
+VRRP_PREEMPT=$8
+
 echo "$1" > "${STATEFILE}.$2"
 
+log_info() 
+{
+		# Writing status
+		echo "VRRP - $VRRP_NAME" 	> /var/vrrp/vrrp-$VRRP_NAME
+		echo "Group $VRRP_ID"  	>> /var/vrrp/vrrp-$VRRP_NAME
+		echo "State is $STATE"	>> /var/vrrp/vrrp-$VRRP_NAME
+		echo "Virtual IP address is $VRRP_IP" >> /var/vrrp/vrrp-$VRRP_NAME
+		echo "Virtual MAC address is $VRRP_MAC" 	>> /var/vrrp/vrrp-$VRRP_NAME
+		echo "$VRRP_NAME is running on $ROUTER_IF" >> /var/vrrp/vrrp-$VRRP_NAME
+		echo "Priority is $VRRP_PRIO "  >> /var/vrrp/vrrp-$VRRP_NAME
+		echo "Advertisement interval is $VRRP_ADV" >> /var/vrrp/vrrp-$VRRP_NAME
+		case "$VRRP_PREEMPT" in
+			"1" )
+				echo "Preemption is true" >> /var/vrrp/vrrp-$VRRP_NAME
+				;;
+			"0" )
+				echo "Preemption is false" >> /var/vrrp/vrrp-$VRRP_NAME
+				;;
+			* )
+				;;
+		esac
+}
+
 case "$1" in
 	"master" )
 		echo "System is becoming master for VRID $2 !"
+		$EBTABLES --zero
+		# Block arp reply for VRRP_IP with real MAC
+		$EBTABLES -A OUTPUT \
+			-p 0X0806 --logical-out $ROUTER_IF -s $ROUTER_MAC \
+			--arp-opcode 2 \
+			--arp-ip-src $VRRP_IP \
+			-j DROP
+		# SNAT on VRRP_MAC dst in incoming packets
+		$EBTABLES -t broute -A BROUTING \
+			--logical-in $ROUTER_IF -p 0x0800 -d $VRRP_MAC \
+			-j redirect 
+		# DNAT on VRRP_MAC src in outgoing packets
+		$EBTABLES -t nat -A POSTROUTING \
+			-p 0x0800 --logical-out $ROUTER_IF \
+			--ip-src $VRRP_IP \
+			-j snat --to-source $VRRP_MAC --snat-target ACCEPT 
+		# Forging good ARP REPLY on VRRP_IP with VRRP_MAC
+		$EBTABLES -t nat -A PREROUTING \
+			-p 0x0806 --logical-in $ROUTER_IF \
+			--arp-opcode 1 --arp-htype 1 --arp-ptype 0x0800 \
+			--arp-ip-dst $VRRP_IP \
+			-j arpreply --arpreply-mac $VRRP_MAC --arpreply-target ACCEPT
+		log_info
 		;;
 	"slave"  )
 		echo "System is becoming slave for VRID $2 !"
+		$EBTABLES --zero
+		# SNAT on VRRP_MAC dst in incoming packets
+		$EBTABLES -t broute -D BROUTING \
+			--logical-in $ROUTER_IF -p 0x0800 -d $VRRP_MAC \
+			-j redirect 
+		# DNAT on VRRP_MAC src in outgoing packets
+		$EBTABLES -t nat -D POSTROUTING \
+			-p 0x0800 --logical-out $ROUTER_IF \
+			--ip-src $VRRP_IP \
+			-j snat --to-source $VRRP_MAC --snat-target ACCEPT 
+		# Forging good ARP REPLY on VRRP_IP with VRRP_MAC
+		$EBTABLES -t nat -D PREROUTING \
+			-p 0x0806 --logical-in $ROUTER_IF \
+			--arp-opcode 1 --arp-htype 1 --arp-ptype 0x0800 \
+			--arp-ip-dst $VRRP_IP \
+			-j arpreply --arpreply-mac $VRRP_MAC --arpreply-target ACCEPT
+		# Block arp reply for VRRP_IP with real MAC
+		$EBTABLES -D OUTPUT \
+			-p 0X0806 --logical-out $ROUTER_IF -s $ROUTER_MAC \
+			--arp-opcode 2 \
+			--arp-ip-src $VRRP_IP \
+			-j DROP
+		log_info
 		;;
 	* )
 		echo "Waouh ! did not understand this !!"
diff -aburN --exclude=.svn vrrpd-1.0/vrrpd.c vrrpd-1.0-patched/vrrpd.c
--- vrrpd-1.0/vrrpd.c	2004-12-05 20:28:15.000000000 +0100
+++ vrrpd-1.0-patched/vrrpd.c	2009-04-08 15:41:20.703630338 +0200
@@ -139,6 +139,26 @@
 struct	ifreq ifr[MAXINTS];
 char	*ifname[MAXINTS];
 
+
+/****************************************************************
+ NAME  : ipaddr_to_str     
+ AIM   : Convert an IP address to a string
+ REMARK  : 
+ CHANGES : 
+****************************************************************/
+char *ipaddr_to_str(uint32_t ipaddr)
+{
+       static char temp_ipaddr[32];
+       snprintf(temp_ipaddr, 32, "%d.%d.%d.%d",
+                       (unsigned char)(ipaddr >> 24& 0xff),
+                       (unsigned char)((ipaddr >> 16) & 0xff),
+                       (unsigned char)((ipaddr >> 8) & 0xff),
+                       (unsigned char)((ipaddr) & 0xff));
+       return temp_ipaddr;
+}
+
+
+
 /****************************************************************
  NAME  : print_buffer                   01/05/23 12:26:27
  AIM  : simple debugging proc
@@ -189,7 +209,7 @@
 ****************************************************************/
 #define HOGRET 0xff
  
-static int stack_hogger(char * inbuf, int kbytes)
+static int stack_hogger(unsigned char * inbuf, int kbytes)
 {
 #ifdef _POSIX_MEMLOCK
 	unsigned char	buf[1024];
@@ -298,6 +318,10 @@
 	// script is expected to reside in a trusted space the consequences
 	// are neligible.
 	FILE  *fext  = fopen( EXTERNAL_SCRIPT, "r" );
+  	vrrp_rt  *vsrv = &glob_vsrv;     
+	vrrp_if  *vif = &vsrv->vif;		 
+	uint32_t addr = vsrv->vaddr[vsrv->naddr-1].addr; /* vrrp addr */
+
 	/* if there is no file */
 	if( !fext ) {
 	 syslog (LOG_INFO,"Will not run external script since it is not available\n");
@@ -319,7 +343,16 @@
 		signal( SIGCHLD, SIG_DFL );
 
 		if (snprintf(command, (size_t) EXTERNAL_SCRIPT_MAX,
-		"%s %s %i", EXTERNAL_SCRIPT, state_string, vrid) < EXTERNAL_SCRIPT_MAX ) {
+					"%s %s %i %s %s %s %i %i %i", 
+					EXTERNAL_SCRIPT, 
+					state_string, 
+					vrid, 
+					ipaddr_to_str(addr), 
+					vif->ifname, 
+					VridName, 
+					vsrv->priority, 
+					vsrv->adver_int/VRRP_TIMER_HZ, 
+					vsrv->preempt) < EXTERNAL_SCRIPT_MAX ) {
 			errorcode = system(command);
 			if (errorcode != 0) {
 				syslog (LOG_ERR,"error: system(%s) returned %i\n",
@@ -342,8 +375,7 @@
   static char pidfile[FILENAME_MAX+1];
   snprintf( pidfile, sizeof(pidfile), "%s/" VRRP_PID_FORMAT
           , PidDir
-          , vsrv->vif.ifname 
-          , vsrv->vrid );
+		  , VridName );
   return pidfile;
 }
 
@@ -1248,7 +1280,7 @@
       snprintf( PidDir, sizeof(PidDir), "%s", optarg );
       break;
     case 'l':
-      snprintf( VridName, sizeof(VridName), "vrrpd->%s", optarg );
+      snprintf( VridName, sizeof(VridName), "%s", optarg );
       break;
     case 'i':
       vif->ifname  = strdup( optarg );
@@ -1395,10 +1427,14 @@
     fprintf(stderr, "the interface ipaddr must be set!\n");
     return -1;
   }
+#if 0   /* We want desactivate use of setting virtual hwaddr with -n 
+		   but we want vrrp using hwadrr while sending vrrp pkts */
   /* make vrrp use the native hwaddr and not the virtual one */
+
   if( vsrv->no_vmac ){
     memcpy( vrrp_hwaddr, vsrv->vif.hwaddr,sizeof(vsrv->vif.hwaddr));
   }
+#endif
   if(( ifname[0] == NULL ) && (vsrv->delt_prio != VRRP_DELTA_DFL )){
     fprintf(stderr, "provide at least one monitored interface!\n");
     return -1;
@@ -1505,22 +1541,6 @@
   return rc;
 }
 
-/****************************************************************
- NAME  : ipaddr_to_str     
- AIM   : Convert an IP address to a string
- REMARK  : 
- CHANGES : 
-****************************************************************/
-char *ipaddr_to_str(uint32_t ipaddr)
-{
-       static char temp_ipaddr[32];
-       snprintf(temp_ipaddr, 32, "%d.%d.%d.%d",
-                       (unsigned char)(ipaddr & 0xff),
-                       (unsigned char)((ipaddr >> 8) & 0xff),
-                       (unsigned char)((ipaddr >> 16) & 0xff),
-                       (unsigned char)((ipaddr >> 24) & 0xff));
-       return temp_ipaddr;
-}
 
 /****************************************************************
  NAME  : state_gotomaster      00/02/07 00:15:26
@@ -1625,6 +1645,7 @@
     VRRP_TIMER_SET( vsrv->ms_down_timer, delay );
     vsrv->state = VRRP_STATE_BACK;
     vrrpd_log(LOG_WARNING, "VRRP ID %d on %s (prio: %d) : %s%swe are now a backup router.", vsrv->vrid, vsrv->vif.ifname, vsrv->priority, master_ipaddr ? ipaddr_to_str(master_ipaddr) : "", master_ipaddr ? " is up, " : "");
+    external_script("slave",vsrv->vrid);
   }
 }
 
diff -aburN --exclude=.svn vrrpd-1.0/vrrpd.h vrrpd-1.0-patched/vrrpd.h
--- vrrpd-1.0/vrrpd.h	2004-12-05 20:16:33.000000000 +0100
+++ vrrpd-1.0-patched/vrrpd.h	2009-03-13 17:27:30.169421457 +0100
@@ -74,10 +74,10 @@
 
 /* implementation specific */
 #define VRRP_PIDDIR_DFL	"/var/run"		/* dir to store the pid file */
-#define VRRP_PID_FORMAT	"vrrpd_%s_%d.pid"	/* pid file format */
+#define VRRP_PID_FORMAT	"vrrpd_vrrp-%s.pid"	/* pid file format */
 #define VRIDNAME_MAX 20				/* name for logging */
 #define EXTERNAL_SCRIPT "/etc/vrrpd/vrrp_switch"
-#define EXTERNAL_SCRIPT_MAX 40			/* size of external script WITH ARGS */
+#define EXTERNAL_SCRIPT_MAX 256		/* size of external script WITH ARGS */
 
 
 typedef struct {	/* parameters per interface -- rfc2338.6.1.1 */
