omapi and agent.remote-id

Jeff Waller jeffw at cnxntech.com
Sun Feb 19 23:03:06 UTC 2012


>From my previous message, check out the function dhcp_host_set_value
in omapi.c, the function there will have various strings that the function will
respond to.  I imagine that the static ip is one of them.


In general the patters is get object then set values; here's some sample code I use,
the function obtain_connection_record is a function I implemented to keep
track of all of the open connections.

The other function, fill_mac_buffer, is something that converts a string to a data item
suitable for use with set_value.  That's a good point too because you'll need to know
what format that data need to be in, is it a string?  Is it bytes?  The source in
omapi.c (or maybe even the documentation) will give you an idea.

Note you should check both the return value of the function as well as waitstatus.

Ill send this to the mailing list too as some others may find it useful.

static isc_result_t retrieve_lease(const char *server_hostname,int server_port,const char *auth_key,const char *auth_secret,const char *mac_address,dhcpctl_handle *lease_handle,int access_flags)
{
   dhcpctl_data_string dhcpctl_lease_hardware_mac_address = 0;
   connection_record *cp = 0;
   isc_result_t result,waitstatus;

   if((result = obtain_connection_record(server_hostname,server_port,auth_key,auth_secret,&cp)) != ISC_R_SUCCESS) return result;
   if((result = omapi_data_string_new(&dhcpctl_lease_hardware_mac_address,6,MDL)) != ISC_R_SUCCESS) return result;
   fill_mac_buffer(dhcpctl_lease_hardware_mac_address->value,mac_address);
   dhcpctl_new_object(lease_handle,cp->connection_handle,"lease");
   dhcpctl_set_value(*lease_handle,dhcpctl_lease_hardware_mac_address,"hardware-address");
   if((result = dhcpctl_open_object(*lease_handle,cp->connection_handle,access_flags)) != ISC_R_SUCCESS) return result;
   if((result = dhcpctl_wait_for_completion(*lease_handle,&waitstatus)) != ISC_R_SUCCESS) return result;
   return waitstatus;
}



On Feb 19, 2012, at 3:23 PM, Matej Mailing wrote:

> Jeff, thanks.
> 
> We are using similar aproach to the different internet package speeds,
> but with groups like:
> 
> group C1-Q1 {
>       log("C1-Q1 - CM");
>       filename "C1-Q1.cfg";
>       option bootfile-name "C1-Q1.cfg";
> }
> for every "contract type".
> 
> Then the group of the host and the host itself is declared via omapi.
> How do you declare a static IP using omapi this way?
> 
> Thanks again,
> Matej
> 
> 2012/2/17 Jeff Waller <jeffw at cnxntech.com>:
>> Sure,
>> 
>> Here's a dhcp.conf from our test system, our objective was to control
>> the filename for cable modems on a class by class basis (you'll note
>> the cm_files include) -- see an except below.  The omapi include is
>> just a key definition.  Don't even need it.
>> 
>> jeffw at yggdrasil ~/src $ cat /usr/local/dhcpd/dhcpd.conf
>> # dhcpd.conf
>> #
>> 
>> # option definitions common to all supported networks...
>> #option domain-name "labs.oc12.net";
>> #option domain-name-servers 216.27.16.82, 4.2.2.1;
>> default-lease-time 600;
>> max-lease-time 7200;
>> #omapi-port 7911;
>> 
>> # Comment to disallow (default)
>> allow leasequery;
>> 
>> # Use this to enble / disable dynamic dns updates globally.
>> ddns-update-style none;
>> 
>> # If this DHCP server is the official DHCP server for the local
>> # network, the authoritative directive should be uncommented.
>> authoritative;
>> 
>> # Use this to send dhcp log messages to a different log file (you also
>> # have to hack syslog.conf to complete the redirection).
>> #log-facility local6;
>> 
>> class "unknown_DOCSIS" {
>>   # only match if first 6 chars of option 61 are docsis
>>   match if (substring(option vendor-class-identifier,0,6) = "docsis");
>> }
>> 
>> class "known_DOCSIS" {
>>   match hardware;
>> }
>> 
>> class "unknown_MTA" {
>>   # only match if first 6 chars of option 61 are docsis
>>   match if (substring(option vendor-class-identifier,0,6) = "pckt1");
>> }
>> 
>> class "known_MTA" {
>>   # only match if first 6 chars of option 61 are docsis
>>   match hardware;
>> }
>> 
>> class "unprovisioned_DOCSIS1" {
>>   match hardware;
>>   filename "10KbD_10KbU.md5";
>> }
>> 
>> class "unprovisioned_DOCSIS2" {
>>   match hardware;
>>   filename "10KbD_10KbU.md6";
>> }
>> 
>> #class "unprovisioned_MTA" {
>> #   match hardware;
>> #   filename "unprovisioned_mta.md5";
>> #}
>> 
>> include "/usr/local/dhcpd/cm_classes.conf";
>> include "/usr/local/dhcpd/omapi.conf";
>> 
>> shared-network localservernet {
>>   subnet 172.16.37.0  netmask 255.255.255.0 {
>>      next-server 172.16.37.2;
>>      option broadcast-address 172.16.37.255;
>>      option domain-name-servers 216.27.16.70;
>>      option tftp-server-name "172.16.37.2";
>>      option time-servers 172.16.37.2;
>>      option routers 172.16.37.1;
>> 
>>      # CPE Pool
>>      pool {
>>         range 172.16.37.250 172.16.37.253;
>>         deny members of "unknown_DOCSIS";
>>         deny members of "known_DOCSIS";
>>      }
>> 
>>      # All UNKNOWN Modems (off the shelf)
>>      pool {
>>         filename "10KbD_10KbU.md5";
>>         range 172.16.37.235 172.16.37.239;
>>         allow members of "unknown_DOCSIS";
>>         deny members of "known_DOCSIS";
>>      }
>> 
>>      # All provisioned Modems
>>      pool {
>>         range 172.16.37.240 172.16.37.249;
>>         allow members of "known_DOCSIS";
>>      }
>>   }
>> 
>>   subnet 172.16.32.0  netmask 255.255.255.0 {
>>      next-server 172.16.32.2;
>>      option broadcast-address 172.16.32.255;
>>      option domain-name-servers 216.27.16.70;
>>      option tftp-server-name "172.16.32.2";
>>      option time-servers 172.16.32.2;
>>      option routers 172.16.32.2;
>>   }
>> }
>> jeffw at yggdrasil ~/src $
>> =======================================================
>> 
>> part of cm_classes, it's alot of the same thing over and over for
>> different speeds, so I'm only including part of it...
>> 
>> jeffw at yggdrasil ~/src $ cat /usr/local/dhcpd/cm_classes.conf
>> class "5xxx_10KbD_10KbU_DOCSIS1" {
>>   match hardware;
>>   filename "5xxx_10KbD_10KbU.md5";
>> }
>> class "5xxx_10KbD_10KbU_DOCSIS2" {
>>   match hardware;
>>   filename "5xxx_10KbD_10KbU.md6";
>> }
>> class "5xxx_768KbD_768KbU_DOCSIS1" {
>>   match hardware;
>>   filename "5xxx_768KbD_768KbU.md5";
>> }
>> class "5xxx_768KbD_768KbU_DOCSIS2" {
>>   match hardware;
>>   filename "5xxx_768KbD_768KbU.md6";
>> }
>> class "5xxx_1.5MbD_1.5MbU_DOCSIS1" {
>>   match hardware;
>>   filename "5xxx_1.5MbD_1.5MbU.md5";
>> }
>> class "5xxx_1.5MbD_1.5MbU_DOCSIS2" {
>>   match hardware;
>>   filename "5xxx_1.5MbD_1.5MbU.md6";
>> }
>> .....
>> 
>> 
>> 
>> On Feb 17, 2012, at 7:11 AM, Matej Mailing wrote:
>> 
>>> Jeff, thanks. I will look at it. Can you please send me some part of
>>> the subclass definitision dhcpd configuration file that you are using
>>> in combination with omapi commands you use in the meantime?
>>> 
>>> Thanks,
>>> Matej
>>> 
>>> 2012/2/17 Jeff Waller <jeffw at cnxntech.com>:
>>>> 
>>>> On Feb 16, 2012, at 5:49 PM, Matej Mailing wrote:
>>>> 
>>>>> For a smaller to middle-sized ISP there is a number of 10k static IP
>>>>> allocations and we are using option 82 agent.remote-id to define them
>>>>> currently as subclasses via the configuration file. As restarting of
>>>>> the DHCP server for every addition / change of the systems behind
>>>>> seems to take quite some time and can (in some cases where the every
>>>>> time-generated configuration file has some errors in it) also stop the
>>>>> server, using omapi with the previously described use case seems to be
>>>>> a good solution. Please correct me if I'm wrong.
>>>> 
>>>> We do a similar thing with OMAPI (9.4K MACS) but using subclasses.  No restart
>>>> necessary.
>>>> 
>>>>> 
>>>>> Jeff, I cant find the patches you mention, could you please help me
>>>>> with some directions on how to find them?
>>>> 
>>>> Here you go:
>>>> 
>>>> https://lists.isc.org/pipermail/dhcp-users/2012-January/006837.html
>>>> 
>>>> Tell me how it works out.
>>>> 
>>>>> 
>>>>> Also if anyone is using a setup I am planning to achieve, please let
>>>>> me know about the performance and known issues.
>>>> 
>>>> Performance:  Takes < 1 second to add/delete.  Not sure about restart
>>>> time to parse the lease file (30 seconds maybe?).
>>>> 
>>>> You should  be prepared to invalidate previous leases as create and delete
>>>> subclasses.
>>>> 
>>>> 
>>>>> 
>>>>> TIA,
>>>>> Matej
>>>>> 
>>>>> 2012/2/16 Jeff Waller <jeffw at cnxntech.com>:
>>>>>> You say subnets, but do you mean subclasses?
>>>>>> 
>>>>>> subclasses are better because it's far more efficient in terms of lookup
>>>>>> complexity.  Subclass lookup is hashed O(1) while host lookup is linear O(n).  Are
>>>>>> you saying new to 4.2 host lookup is also hashed?
>>>>>> 
>>>>>> 
>>>>>> On Feb 16, 2012, at 8:21 AM, Matej Mailing wrote:
>>>>>> 
>>>>>>> Hi,
>>>>>>> 
>>>>>>> I have looked at some posts about the issue but was not successful on
>>>>>>> getting it to work via omapi. My idea is to set a host with its' fixed
>>>>>>> address entirely via omshell. Since 4.2 it is possible to use only
>>>>>>> host declatation for declarding a static IP address to a host (no more
>>>>>>> need to create subnets) and an option of using omapi for such a
>>>>>>> declaration would be very useful for users with large amounts of
>>>>>>> static IP allocations:
>>>>>> 
>>>>>> Can you define large?
>>>>>> 
>>>>>>> 
>>>>>>> host hostname {
>>>>>>> host-identifier option agent.remote-id XX:XX:XX:XX:XX:XX;
>>>>>>> fixed-address aaa.aaa.aaa.aaa;
>>>>>>> }
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>> 
>>>>>>> There is no complete information if it is supported or not on the
>>>>>>> current version or no and I am looking for more information about it.
>>>>>> 
>>>>>> Take a look at the source code for dhcp in server/omapi.c starting
>>>>>> around line 2640
>>>>>> 
>>>>>> in particular the functions
>>>>>> 
>>>>>> dhcp_host_set_value
>>>>>> dhcp_host_get_value
>>>>>> dhcp_host_destroy
>>>>>> dhcp_host_stuff_values
>>>>>> dhcp_host_lookup
>>>>>> dhcp_host_create
>>>>>> 
>>>>>> to get an idea of the values that are supported
>>>>>> 
>>>>>> in addition, there are other supported objects, although (see my post
>>>>>> in January)  some of them are buggy, but you can apply my patches.
>>>>>> 
>>>>>> -Jeff
>>>>>> 
>>>>>>> 
>>>>>>> TIA,
>>>>>>> Matej
>>>>>>> _______________________________________________
>>>>>>> dhcp-hackers mailing list
>>>>>>> dhcp-hackers at lists.isc.org
>>>>>>> https://lists.isc.org/mailman/listinfo/dhcp-hackers
>>>>>> 
>>>> 
>> 



More information about the dhcp-users mailing list