~:: kalyan ::~

failover support for dhcp

The below patch works based on the Brian’s patch The corresponding perl script yet to be fixed for this. I have not done much of testing. This patch helps to read and convert back the configuration in the expected format.

— dhcp-3.0.5/server/ldap.c 2007-04-09 14:40:49.000000000 +0530
+++ dhcp-3.0.5-fv/server/ldap.c 2007-04-09 15:47:13.000000000 +0530
@@ -87,6 +87,37 @@
return strncat(dst, src, dst_size > len ? dst_size – len – 1: 0);
}

+static int
+get_host_entry(char *fqhost, size_t size, char *hostaddr)
+{
+#if defined(MAXHOSTNAMELEN)
+ char hname[MAXHOSTNAMELEN];
+#else
+ char hname[65];
+#endif
+ struct hostent *hp;
+
+ if(NULL == fqhost || 1 >= size)
+ return -1;
+
+ memset(hname, 0, sizeof(hname));
+ if( gethostname(hname, sizeof(hname)-1))
+ return -1;
+
+ if(NULL == (hp = gethostbyname(hname)))
+ return -1;
+
+ strncpy(fqhost, hp->h_name, size-1);
+ fqhost[size-1] = ”;
+
+ if(hostaddr != NULL)
+ {
+ sprintf(hostaddr,”%s”,inet_ntoa(*(struct in_addr*)hp->h_addr));
+ }
+ return 0;
+}
+
+
static void
ldap_parse_class (struct ldap_config_stack *item, struct parse *cfile)
{
@@ -412,7 +443,142 @@
item->close_brace = 1;
}

+static void
+ldap_parse_failover (struct ldap_config_stack *item, struct parse *cfile)
+{
+ char **tempstr;
+ char hostname[257]=””, fqdn[257]=””,hostaddr[64]=””;
+ int primary = 0, split = 1;
+ struct utsname unme;
+
+ uname(&unme);
+ sprintf(hostname, “%s”, unme.nodename);
+ if (get_host_entry (fqdn, sizeof(hostname), hostaddr))
+ {
+ log_info(”Could not get fqdn and the IP address of the host”);
+ }
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverPrimaryServer”)) != NULL)
+ {
+ if (strcmp (tempstr[0], hostname) == 0 || strcmp (tempstr[0], fqdn) == 0 ||
+ strcmp (tempstr[0], hostaddr) == 0 )
+ primary = 1;
+ else
+ primary = 0;
+ ldap_value_free (tempstr);
+ }
+ else
+ {
+ log_error(”Could not decide the server type either primary or secondary for failover peer. Ignoriong.”);
+ return;
+ }
+
+ if ((tempstr = ldap_get_values (ld, item->ldent, “cn”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “failover peer “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, ” { \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if(primary)
+ x_strncat (cfile->inbuf, “primary; \n”, LDAP_BUFFER_SIZE);
+ else
+ x_strncat (cfile->inbuf, “secondary; \n”, LDAP_BUFFER_SIZE);
+
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverPrimaryServer”)) != NULL)
+ {
+ if (primary)
+ x_strncat (cfile->inbuf, “address “, LDAP_BUFFER_SIZE);
+ else
+ x_strncat (cfile->inbuf, “peer address “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverPrimaryPort”)) != NULL)
+ {
+ if (primary)
+ x_strncat (cfile->inbuf, “port “, LDAP_BUFFER_SIZE);
+ else
+ x_strncat (cfile->inbuf, “peer port “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverSecondaryServer”)) != NULL)
+ {
+ if (primary)
+ x_strncat (cfile->inbuf, “peer address “, LDAP_BUFFER_SIZE);
+ else
+ x_strncat (cfile->inbuf, “address “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverSecondaryPort”)) != NULL)
+ {
+ if (primary)
+ x_strncat (cfile->inbuf, “peer port “, LDAP_BUFFER_SIZE);
+ else
+ x_strncat (cfile->inbuf, “port “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverResponseDelay”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “max-response-delay “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverUnackedUpdates”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “max-unacked-updates “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverLoadBalanceTime”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “load balance max seconds “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ( primary && (tempstr = ldap_get_values (ld, item->ldent, “dhcpMaxClientLeadTime”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “mclt “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ if ( primary && (tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverSplit”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “split “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ split = 0;
+ ldap_value_free (tempstr);
+ }
+ if ( primary && split && (tempstr = ldap_get_values (ld, item->ldent, “dhcpFailOverHashBucketAssignment”)) != NULL)
+ {
+ x_strncat (cfile->inbuf, “hba “, LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, tempstr[0], LDAP_BUFFER_SIZE);
+ x_strncat (cfile->inbuf, “; \n”, LDAP_BUFFER_SIZE);
+ ldap_value_free (tempstr);
+ }
+ // Is there any other options can come here? If yes then we need to enable dhcpStatements at schema and here as well.
+ // if ((tempstr = ldap_get_values (ld, item->ldent, “dhcpStatements”)) != NULL)
+ // {
+ // ldap_value_free (tempstr);
+ // }
+
+
+ item->close_brace = 1;

+}
static void
add_to_config_stack (LDAPMessage * res, LDAPMessage * ent)
{
@@ -1142,6 +1308,8 @@
ldap_parse_key (entry, cfile);
else if (strcasecmp (objectClass[i], “dhcpDnsZone”) == 0)
ldap_parse_zone (entry, cfile);
+ else if (strcasecmp (objectClass[i], “dhcpFailOverPeer”) == 0)
+ ldap_parse_failover (entry, cfile);
else if (strcasecmp (objectClass[i], “dhcpHost”) == 0)
{
if (ldap_method == LDAP_METHOD_STATIC)
@@ -1298,32 +1466,6 @@
}

-static int
-getfqhostname(char *fqhost, size_t size)
-{
-#if defined(MAXHOSTNAMELEN)
– char hname[MAXHOSTNAMELEN];
-#else
– char hname[65];
-#endif
– struct hostent *hp;

– if(NULL == fqhost || 1 >= size)
– return -1;

– memset(hname, 0, sizeof(hname));
– if( gethostname(hname, sizeof(hname)-1))
– return -1;

– if(NULL == (hp = gethostbyname(hname)))
– return -1;

– strncpy(fqhost, hp->h_name, size-1);
– fqhost[size-1] = ”;
– return 0;
-}


isc_result_t
ldap_read_config (void)
{
@@ -1359,7 +1501,7 @@
}
else
{
– if(0 == getfqhostname(fqdn, sizeof(fqdn)))
+ if(0 == get_host_entry(fqdn, sizeof(fqdn), NULL))
{
snprintf (hfilter, sizeof (hfilter),
“(&(objectClass=dhcpServer)(|(cn=%s)(cn=%s)))”,

key: dhcp failover ldap

3 Comments »

  1. […] feeling bored little and wrote off the failover support piece for the dhcp. That is available in here . I have not done much of testing. Since it reads the configuration  and convert back to the […]

    Pingback by failover support for dhcp « ~:: kalyan ::~ — April 9, 2007 @ 5:56 pm

  2. dei….ennada proprietary code ippdai net la poddre….CEO ku complaint pannutuma ???

    Comment by kb — August 2, 2007 @ 8:36 am

  3. Machi look for “kalyan” in http://home.ntelos.net/~masneyb/dhcp-3.0.5-ldap-patch
    This is the one part of work i am doing. dhcp is opensource machi.

    Comment by kalyanasundaram — August 3, 2007 @ 1:08 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: