[dhcp-agent-commits] dhcp-agent/src dhcp-lease.c,NONE,1.1 dhcp-lease.h,NONE,1.1 dhcp-server.c,NONE,1
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-02 15:23:44
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9106 Added Files: dhcp-lease.c dhcp-lease.h dhcp-server.c dhcp-server.h dhcp-server-guile.h Log Message: initial server/lease management code --- NEW FILE: dhcp-lease.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v 1.1 2003/07/02 15:23:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #define MODULE_NAME "dhcp-lease" #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-lease.h" #include "dhcp-option.h" /* * * * * * * * * * * * public interface. * * * * * * * * * * * */ lease_constraint_t *lease_constraint_create(int constraint_type, void *data) { lease_constraint_t *constraint = xcalloc(sizeof(lease_constraint_t)); char *hostname; constraint->constraint_type = constraint_type; switch(constraint_type) { case LEASE_CONSTRAINT_HARDWARE_ADDRESS: memcpy(&constraint->data.hw_address.data, data, ETH_ADDR_LEN); break; case LEASE_CONSTRAINT_HOSTNAME: hostname = data; constraint->data.hostname = xstrdup(hostname); break; default: FATAL_MESSAGE("illegal constraint type passed. this is a bug report me."); } return constraint; } void lease_constraint_destroy(lease_constraint_t *constraint) { switch(constraint->constraint_type) { case LEASE_CONSTRAINT_HOSTNAME: xfree(constraint->data.hostname); break; case LEASE_CONSTRAINT_HARDWARE_ADDRESS: /* fall through. */ case LEASE_CONSTRAINT_NONE: /* fall through. */ default: break; } xfree(constraint); return; } lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ip_addr_t ip_addr_range, list_t *options, uint32_t lease_expiry, uint32_t renew_time, uint32_t rebind_time) { dhcp_opt_t *opt, *opt_copy; lease_definition_t *lease_def; lease_def = xcalloc(sizeof(lease_definition_t)); lease_def->constraint = constraint; lease_def->addr_range = ip_addr_range; /* copy our dhcp options we'll pass. */ lease_def->options = list_create(); list_rewind(options); while((opt = list_next(options)) != NULL) { opt_copy = dhcp_option_copy(opt); list_add_to_end(lease_def->options, opt_copy); } /* FIXME: set renew/rebind to defaults if they are passed as zero. */ lease_def->lease_expiry = lease_expiry; lease_def->renew_time = lease_expiry; lease_def->rebind_time = lease_expiry; return lease_def; } void lease_definition_destroy(lease_definition_t *lease_def) { if(lease_def->constraint != NULL) lease_constraint_destroy(lease_def->constraint); dhcp_opt_destroy_option_list(lease_def->options); xfree(lease_def); return; } --- NEW FILE: dhcp-lease.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v 1.1 2003/07/02 15:23:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * DHCP lease data structures and routines. */ #ifndef DHCP_LEASE_H #define DHCP_LEASE_H /* constraints placed on a lease. */ typedef struct { int constraint_type; /* constraint type. */ union { eth_addr_t hw_address; /* hardware address. */ char *hostname; /* hostname. */ } data; } lease_constraint_t; /* lease defintion. */ typedef struct { lease_constraint_t *constraint; /* constraints if any. */ ip_addr_t addr_range; /* address range. */ list_t *options; /* options to be passed. */ uint32_t lease_expiry; /* lease expiry time. */ uint32_t renew_time; /* renewal time. */ uint32_t rebind_time; /* rebind time. */ } lease_definition_t; /* assigned lease data. */ typedef struct { lease_definition_t *defintion; /* lease definition. */ time_t ini_assigned; /* initially assigned timestamp. */ time_t last_assigned; /* last assigned timestamp. */ } assigned_lease_data_t; /* constants. */ enum lease_constraint_type { LEASE_CONSTRAINT_NONE = 0, LEASE_CONSTRAINT_HARDWARE_ADDRESS, LEASE_CONSTRAINT_HOSTNAME }; /* prototypes. */ extern lease_constraint_t *lease_constraint_create(int constraint_type, void *data); extern void lease_constraint_destroy(lease_constraint_t *lease_constraint); extern lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ip_addr_t ip_addr_range, list_t *options, uint32_t lease_expiry, uint32_t renew_time, uint32_t rebind_time); extern void lease_definition_destroy(lease_definition_t *lease_def); #endif /* DHCP_LEASE_H */ --- NEW FILE: dhcp-server.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.c,v 1.1 2003/07/02 15:23:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-lease.h" #include "dhcp-server.h" #include "dhcp-server-guile.h" /* global vars affecting other code. */ char *work_dir = DHCPLOCALSTATE_SERVERDIR; /* our default working directory */ #if !defined(HAVE_PROGNAME) const char *__progname; #endif /* HAVE_PROGNAME */ static unsigned char want_background = 1; /* whether we should go into the background. */ static void do_version(char *interface); static void do_status(char *interface_name); static void do_kill(char *interface_name); static void do_server(char *interface_name); static const char *command_string[] = { "version", "kill", "status", "do server" }; /* table of functions indexed by command codes. */ server_command commands[] = { do_version, /* print out version information. */ do_kill, /* kill server. */ do_status, /* do status. */ do_server, /* do server. */ }; /* print usage info. */ static void usage(char *s) { printf("usage: %s [-aks]\n", s); exit(0); } /* print out version information and exit. */ static void do_version(char *interface) { INFO_MESSAGE("%s version: %s\n", getprogname(), VERSION); } static void do_status(char *interface_name) { INFO_MESSAGE("not implemented yet."); return; } static void do_kill(char *interface_name) { INFO_MESSAGE("not implemented yet."); return; } static void do_server(char *interface_name) { INFO_MESSAGE("not implemented yet."); return; } /* main function: called from scm_boot_guile */ static void real_main(void *closure, int argc, char *argv[]) { int c, command_code = DO_SERVER; char *interface_name = NULL; list_t *interface_list; INFO_MESSAGE("(C) 2003 Thamer Al-Harbash <tm...@wh...>"); INFO_MESSAGE("See LICENSE file for details."); INFO_MESSAGE(" "); while((c = getopt(argc, argv, "vskai:")) != -1) { switch(c) { case 'k': /* kill server. */ command_code = DO_KILL; break; case 's': command_code = DO_STATUS; break; case 'v': command_code = DO_VERSION; break; case 'i': interface_name = xstrdup(optarg); break; case 'a': /* don't fork into the background. */ want_background = 0; break; default: usage(argv[0]); } } /* if all the user wants is version information, give it to him. */ if(command_code == DO_VERSION) { do_version(NULL); exit(0); } /* otherwise anything else requires an up interface. */ if(interface_name == NULL) { interface_list = rawnet_list_active_interfaces(); if(list_get_len(interface_list) == 0) { ERROR_MESSAGE("could not find suitable interface to use while running command: %s", command_string[command_code]); } interface_name = xstrdup(list_first(interface_list)); list_destroy(interface_list, xfree); } /* now that we have an active interface name, go ahead * and run the server command. */ commands[command_code](interface_name); exit(0); } /* actual main: boot guile up so it knows where the bottom of the stack is. */ int main(int argc, char *argv[]) { scm_boot_guile(argc, argv, real_main, NULL); /* get rid of compiler warning. */ exit(1); } --- NEW FILE: dhcp-server.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.h,v 1.1 2003/07/02 15:23:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_SERVER_H #define DHCP_SERVER_H enum command_codes { DO_VERSION = 0, DO_KILL, DO_STATUS, DO_SERVER }; typedef void (*server_command) (char *interface); typedef struct { rawnet_t *rawnet; /* raw network handle * / char *interface_name; /* name of interface */ } dhcp_server_control_t; #endif /* DHCP_SERVER_H */ --- NEW FILE: dhcp-server-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v 1.1 2003/07/02 15:23:30 actmodern Exp $ * * Copyright 2003 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_SERVER_GUILE_H #define DHCP_SERVER_GUILE_H #include <libguile.h> #endif /* DHCP_SERVER_GUILE_H */ |