Date: Mon, 6 Jun 2005 10:20:05 GMT From: Dmitry Sukhodoev <r@chics.ru> To: freebsd-ports-bugs@FreeBSD.org Subject: Re: ports/79599: patch for dhcp lease query, used in cisco uBRs' Message-ID: <200506061020.j56AK5An061706@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/79599; it has been noted by GNATS. From: Dmitry Sukhodoev <r@chics.ru> To: bug-followup@FreeBSD.org Cc: sem@FreeBSD.org Subject: Re: ports/79599: patch for dhcp lease query, used in cisco uBRs' Date: Mon, 06 Jun 2005 16:16:24 +0600 here is patch for new option in port. === cut === diff -ruN ../isc-dhcp3-server.original/Makefile ./Makefile --- ../isc-dhcp3-server.original/Makefile Mon Jun 6 15:39:27 2005 +++ ./Makefile Mon Jun 6 16:06:10 2005 @@ -34,7 +34,8 @@ DHCP_LDAP "add experimental LDAP backend support" off \ DHCP_LDAP_SSL "support LDAP connection over SSL/TLS" on \ OPENSSL_BASE "use the base system OpenSSL (required by TLS)" on \ - OPENSSL_PORT "use OpenSSL from ports (required by TLS)" off + OPENSSL_PORT "use OpenSSL from ports (required by TLS)" off \ + PATCH_DLQ "use DHCPLEASEDQUERY patch for cisco uBRs'" off .endif .include <bsd.port.pre.mk> @@ -200,7 +201,8 @@ post-patch: patch-scripts patch-makefile-conf \ patch-makefiles-dist patch-man-pages \ patch-pkgmessage patch-site-conf \ - patch-rc-scripts + patch-rc-scripts \ + patch-dlq patch-scripts: @${REINPLACE_CMD} ${REINPLACE_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \ @@ -258,6 +260,11 @@ .else @${REINPLACE_CMD} -e '/^%%LDAP%%/d' ${PKGMESSAGE} .endif +.endif + +patch-dlq: +.if defined(WITH_PATCH_DLQ) + @${PATCH} ${PATCH_ARGS} < ${PATCHDIR}/extra-patch-dlq .endif # Post-install diff -ruN ../isc-dhcp3-server.original/files/extra-patch-dlq ./files/extra-patch-dlq --- ../isc-dhcp3-server.original/files/extra-patch-dlq Thu Jan 1 05:00:00 1970 +++ ./files/extra-patch-dlq Mon Jun 6 14:51:12 2005 @@ -0,0 +1,261 @@ +diff -ruN ../../work/dhcp-3.0.2/includes/dhcp.h ./includes/dhcp.h +--- ../../work/dhcp-3.0.2/includes/dhcp.h Thu Jun 10 23:59:29 2004 ++++ ./includes/dhcp.h Mon Jun 6 14:45:47 2005 +@@ -168,6 +168,11 @@ + #define DHCPNAK 6 + #define DHCPRELEASE 7 + #define DHCPINFORM 8 ++#define DHCPLEASEQUERY 13 ++#define DHCPLEASEKNOWN 14 ++#define DHCPLEASEUNKNOWN 15 ++#define DHCPLEASEACTIVE 16 ++#define DHCPUNIMPLEMENTED 17 + + /* Relay Agent Information option subtypes: */ + #define RAI_CIRCUIT_ID 1 +diff -ruN ../../work/dhcp-3.0.2/includes/dhcpd.h ./includes/dhcpd.h +--- ../../work/dhcp-3.0.2/includes/dhcpd.h Mon Jun 6 14:48:58 2005 ++++ ./includes/dhcpd.h Mon Jun 6 14:46:21 2005 +@@ -1374,6 +1374,7 @@ + void dhcprelease PROTO ((struct packet *, int)); + void dhcpdecline PROTO ((struct packet *, int)); + void dhcpinform PROTO ((struct packet *, int)); ++void dhcpleasequery PROTO ((struct packet *, int)); + void nak_lease PROTO ((struct packet *, struct iaddr *cip)); + void ack_lease PROTO ((struct packet *, struct lease *, + unsigned int, TIME, char *, int)); +diff -ruN ../../work/dhcp-3.0.2/server/Makefile.dist ./server/Makefile.dist +--- ../../work/dhcp-3.0.2/server/Makefile.dist Mon Jun 6 14:48:58 2005 ++++ ./server/Makefile.dist Mon Jun 6 14:47:06 2005 +@@ -25,9 +25,9 @@ + CATMANPAGES = dhcpd.cat8 dhcpd.conf.cat5 dhcpd.leases.cat5 + SEDMANPAGES = dhcpd.man8 dhcpd.conf.man5 dhcpd.leases.man5 + SRCS = dhcpd.c dhcp.c bootp.c confpars.c db.c class.c failover.c \ +- omapi.c mdb.c stables.c salloc.c ddns.c ++ omapi.c mdb.c stables.c salloc.c ddns.c dhcpleasequery.c + OBJS = dhcpd.o dhcp.o bootp.o confpars.o db.o class.o failover.o \ +- omapi.o mdb.o stables.o salloc.o ddns.o ++ omapi.o mdb.o stables.o salloc.o ddns.o dhcpleasequery.o + PROG = dhcpd + MAN = dhcpd.8 dhcpd.conf.5 dhcpd.leases.5 + +diff -ruN ../../work/dhcp-3.0.2/server/dhcp.c ./server/dhcp.c +--- ../../work/dhcp-3.0.2/server/dhcp.c Wed Nov 24 22:39:19 2004 ++++ ./server/dhcp.c Mon Jun 6 14:48:04 2005 +@@ -226,6 +226,13 @@ + case DHCPACK: + case DHCPOFFER: + case DHCPNAK: ++ case DHCPLEASEACTIVE: ++ case DHCPLEASEKNOWN: ++ case DHCPLEASEUNKNOWN: ++ break; ++ ++ case DHCPLEASEQUERY: ++ dhcpleasequery(packet, ms_nulltp); + break; + + default: +diff -ruN ../../work/dhcp-3.0.2/server/dhcpleasequery.c ./server/dhcpleasequery.c +--- ../../work/dhcp-3.0.2/server/dhcpleasequery.c Thu Jan 1 05:00:00 1970 ++++ ./server/dhcpleasequery.c Mon Jun 6 14:48:20 2005 +@@ -0,0 +1,199 @@ ++#include "dhcpd.h" ++ ++void dhcpleasequery (packet, ms_nulltp) ++struct packet *packet; ++int ms_nulltp; ++{ ++ ++ //printf("Received LEASEQUERY message\n"); ++ struct lease *lease = (struct lease *)0; ++ struct iaddr cip; ++ struct sockaddr_in to; ++ //unsigned packet_length; ++ unsigned char dhcpMsgType; ++ struct dhcp_packet *raw = packet -> raw; ++ struct option_state *options = (struct option_state *)0; ++ struct option_cache *oc = (struct option_cache *)0; ++ struct data_string prl; ++ char msgbuf [1024]; ++ uint leaseTime; ++ ++ option_state_allocate(&options, MDL); ++ cip.len = sizeof packet -> raw -> ciaddr; ++ memcpy (cip.iabuf, &packet -> raw -> ciaddr, sizeof packet -> raw -> ciaddr); ++ //TODO if IP is all zeros, then set dhcp message type to DHCPUNIMPLEMENTED ++ find_lease_by_ip_addr(&lease, cip, MDL); ++ ++ if(!lease) { ++ dhcpMsgType = DHCPNAK; ++ snprintf( ++ msgbuf, ++ sizeof msgbuf, ++ "DHCPLEASEQUERY failed for c:%s, y:%s, s:%s, g:%s", ++ inet_ntoa(packet -> raw -> ciaddr), ++ inet_ntoa(packet -> raw -> yiaddr), ++ inet_ntoa(packet -> raw -> siaddr), ++ inet_ntoa(packet -> raw -> giaddr) ++ ); ++ log_info(msgbuf); ++ } else { ++ if(lease -> binding_state == FTS_ACTIVE) { ++ dhcpMsgType = DHCPACK; ++ log_info("DHCPLEASEQUERY success"); ++ } else { ++ dhcpMsgType = DHCPNAK; ++ } ++ memcpy(packet -> raw -> chaddr, ++ &lease -> hardware_addr.hbuf [1], sizeof packet -> raw -> chaddr); ++ packet -> raw -> hlen = lease -> hardware_addr.hlen - 1; ++ packet -> raw -> htype = lease -> hardware_addr.hbuf [0]; ++ ++ if(dhcpMsgType == DHCPACK && lease -> ends > cur_time) { ++ if(!option_cache_allocate(&oc, MDL)) { ++ log_error("No memory for lease time option."); ++ option_state_dereference(&options, MDL); ++ return; ++ } ++ leaseTime = htonl(lease -> ends - cur_time); ++ if (!make_const_data(&oc -> expression, (char*)&leaseTime, sizeof leaseTime, 0, 0, MDL)) { ++ log_error("No memory for expr_const expression."); ++ option_cache_dereference(&oc, MDL); ++ option_state_dereference(&options, MDL); ++ return; ++ } ++ oc -> option = dhcp_universe.options[DHO_DHCP_LEASE_TIME]; ++ save_option(&dhcp_universe, options, oc); ++ option_cache_dereference(&oc, MDL); ++ } ++ ++ // Set the relay agent info. ++ if(lease -> agent_options) { ++ pair p; ++ int len = 0; ++ char agent_options[255]; ++ for(p = lease -> agent_options -> first; p; p = p -> cdr) { ++ oc = (struct option_cache *)p -> car; ++ if(oc -> data.len) { ++ memcpy(&agent_options[len], (char*)&oc->option->code, 1); ++ memcpy(&agent_options[len+1], (char*)&oc->data.len, 1); ++ memcpy(&agent_options[len+2], oc->data.data, oc->data.len); ++ len += oc -> data.len + 2; ++ } ++ } ++ oc = (struct option_cache *)0; ++ if(!option_cache_allocate (&oc, MDL)) { ++ log_error("No memory for lease time option."); ++ option_state_dereference (&options, MDL); ++ return; ++ } ++ if(!make_const_data(&oc -> expression, (char*)&agent_options, len, 0, 0, MDL)) { ++ log_error("No memory for expr_const expression."); ++ option_cache_dereference(&oc, MDL); ++ option_state_dereference(&options, MDL); ++ return; ++ } ++ oc -> option = dhcp_universe.options[DHO_DHCP_AGENT_OPTIONS]; ++ save_option(&dhcp_universe, options, oc); ++ option_cache_dereference(&oc, MDL); ++ } ++ } ++ ++ // Set the message type ++ packet -> raw -> op = BOOTREPLY; ++ ++ // Set dhcp message type ++ if(!option_cache_allocate(&oc, MDL)) { ++ log_error("No memory for dhcp message type."); ++ option_state_dereference(&options, MDL); ++ return; ++ } ++ if(!make_const_data(&oc -> expression, &dhcpMsgType, sizeof dhcpMsgType, 0, 0, MDL)) { ++ log_error("No memory for expr_const expression."); ++ option_cache_dereference(&oc, MDL); ++ option_state_dereference(&options, MDL); ++ return; ++ } ++ oc -> option = dhcp_universe.options[DHO_DHCP_MESSAGE_TYPE]; ++ save_option(&dhcp_universe, options, oc); ++ option_cache_dereference(&oc, MDL); ++ ++ ++#if 0 ++ memset(&prl, 0, sizeof prl); ++ ++ /* Use the parameter list from the scope if there is one. */ ++ oc = lookup_option( ++ &dhcp_universe, ++ options, ++ DHO_DHCP_PARAMETER_REQUEST_LIST ++ ); ++ ++ /* Otherwise, if the client has provided a list of options ++ that it wishes returned, use it to prioritize. Otherwise, ++ prioritize based on the default priority list. */ ++ ++ if (!oc) oc = lookup_option(&dhcp_universe, packet -> options, DHO_DHCP_PARAMETER_REQUEST_LIST); ++ if (oc) evaluate_option_cache(&prl, packet, (struct lease *)0, (struct client_state *)0, packet -> options, options, &global_scope, oc, MDL); ++ ++ //printf("Parameter Request List length is %d: %d, %d\n", prl.len, prl.data[0], prl.data[1]); ++ ++ /* Set up the option buffer... */ ++ packet -> packet_length = cons_options( ++ packet, ++ raw, ++ lease, ++ (struct client_state *)0, ++ 0, ++ packet -> options, ++ options, ++ &global_scope, ++ 0, ++ 0, ++ 0, ++ prl.len ? &prl : (struct data_string *)0, ++ (char *)0 ++ ); ++#endif ++ ++ /* Set up the option buffer... */ ++ packet -> packet_length = cons_options( ++ packet, ++ raw, ++ lease, ++ (struct client_state *)0, ++ 0, ++ packet -> options, ++ options, ++ &global_scope, ++ 0, 0, 0, ++ (struct data_string *)0, ++ (char *)0 ++ ); ++ option_state_dereference(&options, MDL); ++ ++ to.sin_family = AF_INET; ++#ifdef HAVE_SA_LEN ++ to.sin_len = sizeof to; ++#endif ++ memset(to.sin_zero, 0, sizeof to.sin_zero); ++ ++ /* LEASEQUERY packets must be sent to gateway address */ ++ if(packet -> raw -> giaddr.s_addr) { ++ to.sin_addr = packet -> raw -> giaddr; ++ if (packet -> raw -> giaddr.s_addr != htonl(INADDR_LOOPBACK)) { ++ to.sin_port = local_port; ++ } else { ++ to.sin_port = remote_port; /* For debugging. */ ++ } ++ ++ if (fallback_interface) { ++ send_packet( ++ fallback_interface, ++ (struct packet *)0, ++ packet -> raw, packet -> packet_length, ++ packet -> raw -> siaddr, &to, ++ (struct hardware *)0 ++ ); ++ } ++ } ++} === cut === -- Dmitry Sukhodoev, servers maintainer of chics.ru
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200506061020.j56AK5An061706>