dhcp-agent-commits Mailing List for dhcp-agent (Page 10)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <act...@us...> - 2003-08-17 00:58:00
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26708/src Modified Files: dhcp-lease-guile.c dhcp-lease-guile.h Log Message: added more lease smobs Index: dhcp-lease-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease-guile.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-lease-guile.c 12 Aug 2003 12:05:47 -0000 1.1 --- dhcp-lease-guile.c 17 Aug 2003 00:57:57 -0000 1.2 *************** *** 21,25 **** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * lease smob */ --- 21,25 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * lease smobs */ *************** *** 33,37 **** #include "dhcp-lease-guile.h" ! static scm_t_bits lease_tag; /* mark a lease: we don't need to do any marking. */ --- 33,41 ---- #include "dhcp-lease-guile.h" ! static scm_t_bits lease_tag, lease_def_tag, lease_constraint_tag; ! ! /* * * * * * * * * * * ! * lease smob * ! * * * * * * * * * * */ /* mark a lease: we don't need to do any marking. */ *************** *** 416,418 **** --- 420,774 ---- lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return lease_copy(lease_smob->lease); + } + + /* * * * * * * * * * * + * lease def smob * + * * * * * * * * * * */ + + /* mark a lease_def: we don't need to do any marking. */ + static SCM scm_lease_def_mark(SCM scm_lease_def) + { + return SCM_BOOL_F; + } + + /* free a lease scm. */ + static size_t scm_lease_def_free(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def; + + lease_def = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + lease_definition_destroy(lease_def->lease_def); + xfree(lease_def); + + return sizeof(lease_definition_smob_t); + } + + /* print out a lease def scm. */ + static int scm_lease_def_print(SCM scm_lease_def, SCM port, scm_print_state *pstate) + { + scm_puts("#<lease_def>", port); + return 1; + } + + /* create an SCM lease_def: this is called from the C code: a + copy is made so garbage collection doesn't clubber our copy */ + SCM scm_lease_def_c2scm(lease_definition_t *lease_def) + { + lease_definition_smob_t *lease_def_smob; + lease_definition_t *new_lease_def; + + new_lease_def = lease_definition_copy(lease_def); + lease_def_smob = scm_must_malloc(sizeof(lease_definition_smob_t), "lease-def-make"); + lease_def_smob->lease_def = new_lease_def; + + SCM_RETURN_NEWSMOB(lease_def_tag, lease_def_smob); + } + + /* create an SCM lease: this is called from the C code: no copy is made. */ + SCM scm_lease_def_c2scm_x(lease_definition_t *lease_def) + { + lease_definition_smob_t *lease_def_smob; + + lease_def_smob = scm_must_malloc(sizeof(lease_definition_smob_t), "lease-def-make"); + lease_def_smob->lease_def = lease_def; + + SCM_RETURN_NEWSMOB(lease_def_tag, lease_def_smob); + } + + /* get type of lease definition. */ + static SCM scm_lease_def_get_type(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-type"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + + switch(lease_definition_get_type(lease_def_smob->lease_def)) { + + case LEASE_SINGLE_ADDRESS: + return scm_str2symbol("lease-type-single-address"); + + case LEASE_RANGE_ADDRESS: + return scm_str2symbol("lease-type-range-address"); + + default: + return scm_str2symbol("lease-type-unknown"); + + } + } + + /* get constraint from lease definition. */ + static SCM scm_lease_def_get_constraint(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + lease_constraint_t *lease_constraint; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-constraint"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + lease_constraint = lease_definition_get_constraint(lease_def_smob->lease_def); + + return scm_lease_constraint_c2scm(lease_constraint); + } + + /* get bottom address from lease definition. */ + static SCM scm_lease_def_get_bottom_addr(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-bottom-addr"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_bottom_addr(lease_def_smob->lease_def)); + } + + /* get top address from lease definition. */ + static SCM scm_lease_def_get_top_addr(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-top-addr"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_top_addr(lease_def_smob->lease_def)); + } + + /* get subnet address on lease definition. */ + static SCM scm_lease_def_get_subnet_addr(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-subnet-addr"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_subnet_addr(lease_def_smob->lease_def)); + } + + /* get subnet mask on lease definition. */ + static SCM scm_lease_def_get_subnet_mask(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-subnet-mask"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_subnet_mask(lease_def_smob->lease_def)); + } + + /* get subnet address on lease definition. */ + static SCM scm_lease_def_get_options(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-subnet-mask"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return scm_dhcp_opt_c_list_to_list(lease_definition_get_options(lease_def_smob->lease_def)); + } + + /* get renew time on lease definition. */ + static SCM scm_lease_def_get_renew(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-renew"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_renew(lease_def_smob->lease_def)); + } + + /* get rebind time on lease definition. */ + static SCM scm_lease_def_get_rebind(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-rebind"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + return SCM_MAKINUM(lease_definition_get_rebind(lease_def_smob->lease_def)); + } + + /* get expiry time on lease definition. */ + static SCM scm_lease_def_get_expiry(SCM scm_lease_def) + { + lease_definition_smob_t *lease_def_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_def_tag, scm_lease_def), + scm_lease_def, SCM_ARG1, "lease-def-get-expiry"); + + lease_def_smob = (lease_definition_smob_t *)SCM_SMOB_DATA(scm_lease_def); + + return SCM_MAKINUM(lease_definition_get_expiry(lease_def_smob->lease_def)); + } + + /* initialization routines for lease definition smob. */ + void init_lease_def_smob(void) + { + lease_def_tag = scm_make_smob_type("lease-def", sizeof(lease_definition_smob_t)); + + scm_set_smob_free(lease_def_tag, scm_lease_def_free); + scm_set_smob_mark(lease_def_tag, scm_lease_def_mark); + scm_set_smob_print(lease_def_tag, scm_lease_def_print); + + scm_c_define_gsubr("lease-def-get-type", 1, 0, 0, scm_lease_def_get_type); + scm_c_define_gsubr("lease-def-get-constraint", 1, 0, 0, scm_lease_def_get_constraint); + scm_c_define_gsubr("lease-def-get-bottom-addr", 1, 0, 0, scm_lease_def_get_bottom_addr); + scm_c_define_gsubr("lease-def-get-top-addr", 1, 0, 0, scm_lease_def_get_top_addr); + scm_c_define_gsubr("lease-def-get-subnet-addr", 1, 0, 0, scm_lease_def_get_subnet_addr); + scm_c_define_gsubr("lease-def-get-subnet-mask", 1, 0, 0, scm_lease_def_get_subnet_mask); + scm_c_define_gsubr("lease-def-get-options", 1, 0, 0, scm_lease_def_get_options); + scm_c_define_gsubr("lease-def-get-renew", 1, 0, 0, scm_lease_def_get_renew); + scm_c_define_gsubr("lease-def-get-rebind", 1, 0, 0, scm_lease_def_get_rebind); + scm_c_define_gsubr("lease-def-get-expiry", 1, 0, 0, scm_lease_def_get_expiry); + + return; + } + + /* * * * * * * * * * * * * * * + * lease definition smob * + * * * * * * * * * * * * * * */ + + /* mark a lease_constraint: we don't need to do any marking. */ + static SCM scm_lease_constraint_mark(SCM scm_lease_constraint) + { + return SCM_BOOL_F; + } + + /* free a lease constraint scm. */ + static size_t scm_lease_constraint_free(SCM scm_lease_constraint) + { + lease_constraint_smob_t *lease_constraint; + + lease_constraint = (lease_constraint_smob_t *)SCM_SMOB_DATA(scm_lease_constraint); + lease_constraint_destroy(lease_constraint->lease_constraint); + xfree(lease_constraint); + + return sizeof(lease_constraint_smob_t); + } + + /* print out a lease constraint scm. */ + static int scm_lease_constraint_print(SCM scm_lease_constraint, SCM port, scm_print_state *pstate) + { + scm_puts("#<lease_constraint>", port); + return 1; + } + + /* create an SCM lease_constraint: this is called from the C code: a + copy is made so garbage collection doesn't clubber our copy */ + SCM scm_lease_constraint_c2scm(lease_constraint_t *lease_constraint) + { + lease_constraint_smob_t *lease_constraint_smob; + lease_constraint_t *new_lease_constraint; + + new_lease_constraint = lease_constraint_copy(lease_constraint); + lease_constraint_smob = scm_must_malloc(sizeof(lease_constraint_smob_t), "lease-constraint-make"); + lease_constraint_smob->lease_constraint = new_lease_constraint; + + SCM_RETURN_NEWSMOB(lease_constraint_tag, lease_constraint_smob); + } + + /* create an SCM lease constraint: this is called from the C code: no copy is made. */ + SCM scm_lease_constraint_c2scm_x(lease_constraint_t *lease_constraint) + { + lease_constraint_smob_t *lease_constraint_smob; + + lease_constraint_smob = scm_must_malloc(sizeof(lease_constraint_smob_t), "lease-constraint-make"); + lease_constraint_smob->lease_constraint = lease_constraint; + + SCM_RETURN_NEWSMOB(lease_constraint_tag, lease_constraint_smob); + } + + /* get constraint type. */ + static SCM scm_lease_constraint_get_type(SCM scm_lease_constraint) + { + lease_constraint_smob_t *lease_constraint_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_constraint_tag, scm_lease_constraint), + scm_lease_constraint, SCM_ARG1, "lease-constraint-get-type"); + + lease_constraint_smob = (lease_constraint_smob_t *)SCM_SMOB_DATA(scm_lease_constraint); + + switch(lease_constraint_get_type(lease_constraint_smob->lease_constraint)) { + + case LEASE_CONSTRAINT_NONE: + return scm_str2symbol("lease-constraint-none"); + + case LEASE_CONSTRAINT_HARDWARE_ADDRESS: + return scm_str2symbol("lease-constraint-hw-address"); + + case LEASE_CONSTRAINT_HOSTNAME: + return scm_str2symbol("lease-constraint-hostname"); + + default: + return scm_str2symbol("lease-constraint-type-unknown"); + } + } + + /* get constraint hostname. */ + static SCM scm_lease_constraint_get_hostname(SCM scm_lease_constraint) + { + lease_constraint_smob_t *lease_constraint_smob; + const char *hostname; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_constraint_tag, scm_lease_constraint), + scm_lease_constraint, SCM_ARG1, "lease-constraint-get-type"); + + lease_constraint_smob = (lease_constraint_smob_t *)SCM_SMOB_DATA(scm_lease_constraint); + hostname = lease_constraint_get_hostname(lease_constraint_smob->lease_constraint); + + if(hostname == NULL) + return SCM_BOOL_F; + else + return scm_makfrom0str(hostname); + } + + /* get constraint hw address. */ + static SCM scm_lease_constraint_get_hw_address(SCM scm_lease_constraint) + { + lease_constraint_smob_t *lease_constraint_smob; + eth_addr_t eth_addr; + char *eth_str; + SCM scm_eth_str; + + SCM_ASSERT(SCM_SMOB_PREDICATE(lease_constraint_tag, scm_lease_constraint), + scm_lease_constraint, SCM_ARG1, "lease-constraint-get-type"); + + lease_constraint_smob = (lease_constraint_smob_t *)SCM_SMOB_DATA(scm_lease_constraint); + + if(lease_constraint_get_type(lease_constraint_smob->lease_constraint) != LEASE_CONSTRAINT_HARDWARE_ADDRESS) { + return SCM_BOOL_F; + } + + eth_addr = lease_constraint_get_hw_address(lease_constraint_smob->lease_constraint); + eth_str = eth_addr_to_string(eth_addr); + scm_eth_str = scm_makfrom0str(eth_str); + xfree(eth_str); + + return scm_eth_str; + } + + /* init lease constraint smob. */ + void init_lease_constraint_smob(void) + { + lease_constraint_tag = scm_make_smob_type("lease-constraint", sizeof(lease_constraint_smob_t)); + + scm_set_smob_free(lease_constraint_tag, scm_lease_constraint_free); + scm_set_smob_mark(lease_constraint_tag, scm_lease_constraint_mark); + scm_set_smob_print(lease_constraint_tag, scm_lease_constraint_print); + + scm_c_define_gsubr("lease-constraint-get-type", 1, 0, 0, scm_lease_constraint_get_type); + scm_c_define_gsubr("lease-constraint-get-hostname", 1, 0, 0, scm_lease_constraint_get_hostname); + scm_c_define_gsubr("lease-constraint-get-hw-address", 1, 0, 0, scm_lease_constraint_get_hw_address); + + return; } Index: dhcp-lease-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease-guile.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-lease-guile.h 12 Aug 2003 12:05:47 -0000 1.1 --- dhcp-lease-guile.h 17 Aug 2003 00:57:57 -0000 1.2 *************** *** 32,35 **** --- 32,43 ---- } lease_smob_t; + typedef struct { + lease_definition_t *lease_def; + } lease_definition_smob_t; + + typedef struct { + lease_constraint_t *lease_constraint; + } lease_constraint_smob_t; + extern void init_lease_smob(void); extern lease_t *scm_c_get_lease(SCM scm_lease); *************** *** 37,40 **** extern SCM scm_lease_c2scm_x(lease_t *lease); ! #endif /* DHCP_LEASE_GUILE_H */ --- 45,55 ---- extern SCM scm_lease_c2scm_x(lease_t *lease); ! extern void init_lease_def_smob(void); ! extern SCM scm_lease_def_c2scm(lease_definition_t *lease_def); ! extern SCM scm_lease_def_c2scm_x(lease_definition_t *lease_def); ! ! extern void init_lease_constraint_smob(void); ! extern SCM scm_lease_constraint_c2scm(lease_constraint_t *lease_constraint); ! extern SCM scm_lease_constraint_c2scm_x(lease_constraint_t *lease_constraint); + #endif /* DHCP_LEASE_GUILE_H */ |
From: <act...@us...> - 2003-08-17 00:57:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26666/src Modified Files: dhcp-lease.c dhcp-lease.h Log Message: added lease datum copying code Index: dhcp-lease.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-lease.c 5 Aug 2003 04:59:12 -0000 1.8 --- dhcp-lease.c 17 Aug 2003 00:57:33 -0000 1.9 *************** *** 84,87 **** --- 84,119 ---- } + lease_constraint_t *lease_constraint_copy(lease_constraint_t *lease_constraint) + { + lease_constraint_t *new_lease_constraint; + eth_addr_t eth_addr; + char *hostname = NULL; /* ugh. need to xstrdup because of const. */ + void *data; + + switch(lease_constraint->constraint_type) { + + case LEASE_CONSTRAINT_HOSTNAME: + hostname = xstrdup(lease_constraint_get_hostname(lease_constraint)); + data = hostname; + break; + + case LEASE_CONSTRAINT_HARDWARE_ADDRESS: + eth_addr = lease_constraint_get_hw_address(lease_constraint); + data = ð_addr; + break; + + default: + data = NULL; + + } + + new_lease_constraint = lease_constraint_create(lease_constraint->constraint_type, data); + + if(hostname) + xfree(hostname); + + return new_lease_constraint; + } + lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ip_addr_t subnet_address, *************** *** 138,141 **** --- 170,191 ---- } + lease_definition_t *lease_definition_copy(lease_definition_t *lease_def) + { + list_t *options; + lease_constraint_t *lease_constraint; + lease_definition_t *new_lease_def; + + lease_constraint = lease_constraint_copy(lease_definition_get_constraint(lease_def)); + options = dhcp_option_copy_list(lease_definition_get_options(lease_def)); + + /* from here on in we can just copy out and reassign the pointers. */ + new_lease_def = xcalloc(sizeof(lease_definition_t)); + *new_lease_def = *lease_def; + new_lease_def-> options = options; + new_lease_def->constraint = lease_constraint; + + return new_lease_def; + } + void lease_definition_destroy(lease_definition_t *lease_def) { *************** *** 224,228 **** /* lease definition. */ ! const char *lease_type_to_string(lease_definition_t *lease) { int lease_type = lease->lease_type; --- 274,278 ---- /* lease definition. */ ! const char *lease_definition_type_to_string(lease_definition_t *lease) { int lease_type = lease->lease_type; *************** *** 377,381 **** char *subnet_addr, *subnet_mask; ! INFO_MESSAGE("Lease type: %s", lease_type_to_string(lease_def)); switch(lease_definition_get_type(lease_def)) { --- 427,431 ---- char *subnet_addr, *subnet_mask; ! INFO_MESSAGE("Lease type: %s", lease_definition_type_to_string(lease_def)); switch(lease_definition_get_type(lease_def)) { Index: dhcp-lease.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-lease.h 5 Aug 2003 04:59:12 -0000 1.7 --- dhcp-lease.h 17 Aug 2003 00:57:33 -0000 1.8 *************** *** 92,95 **** --- 92,97 ---- extern lease_constraint_t *lease_constraint_create(int constraint_type, void *data); extern void lease_constraint_destroy(lease_constraint_t *lease_constraint); + extern lease_constraint_t *lease_constraint_copy(lease_constraint_t *lease_constraint); + extern lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ip_addr_t subnet, *************** *** 108,118 **** extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); extern eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint); ! extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); ! extern eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint); ! extern const char *lease_type_to_string(lease_definition_t *lease); extern int lease_definition_get_type(lease_definition_t *lease); extern lease_constraint_t *lease_definition_get_constraint(lease_definition_t *lease); - extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); extern ip_addr_t lease_definition_get_bottom_addr(lease_definition_t *lease); extern ip_addr_t lease_definition_get_top_addr(lease_definition_t *lease); --- 110,118 ---- extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); extern eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint); ! extern lease_constraint_t *lease_constraint_copy(lease_constraint_t *lease_constraint); ! extern const char *lease_definition_type_to_string(lease_definition_t *lease); extern int lease_definition_get_type(lease_definition_t *lease); extern lease_constraint_t *lease_definition_get_constraint(lease_definition_t *lease); extern ip_addr_t lease_definition_get_bottom_addr(lease_definition_t *lease); extern ip_addr_t lease_definition_get_top_addr(lease_definition_t *lease); *************** *** 124,127 **** --- 124,128 ---- extern uint32_t lease_definition_get_rebind(lease_definition_t *lease); extern uint32_t lease_definition_get_expiry(lease_definition_t *lease); + extern lease_definition_t *lease_definition_copy(lease_definition_t *lease_def); extern list_t *lease_get_options(lease_t *lease_data); |
From: <act...@us...> - 2003-08-12 12:28:12
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv21956 Added Files: dhcp-lease-guile.c dhcp-lease-guile.h Log Message: lease smob moved to seperate source; now more complete --- NEW FILE: dhcp-lease-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease-guile.c,v 1.1 2003/08/12 12:05:47 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. * * lease smob */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-guile-util.h" #include "dhcp-lease.h" #include "dhcp-option-guile.h" #include "dhcp-lease-guile.h" static scm_t_bits lease_tag; /* mark a lease: we don't need to do any marking. */ static SCM scm_lease_mark(SCM scm_lease) { return SCM_BOOL_F; } /* free a lease scm. */ static size_t scm_lease_free(SCM scm_lease) { lease_smob_t *lease; lease = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); lease_destroy(lease->lease); xfree(lease); return sizeof(lease_smob_t); } /* print out a lease scm. */ static int scm_lease_print(SCM scm_lease, SCM port, scm_print_state *pstate) { scm_puts("#<lease>", port); return 1; } /* create an SCM lease: this is called from the C code: a copy is made so garbage collection doesn't clubber our copy */ SCM scm_lease_c2scm(lease_t *lease) { lease_smob_t *lease_smob; lease_t *new_lease; new_lease = lease_copy(lease); lease_smob = scm_must_malloc(sizeof(lease_smob_t), "lease-make"); lease_smob->lease = new_lease; SCM_RETURN_NEWSMOB(lease_tag, lease_smob); } /* create an SCM lease: this is called from the C code: no copy is made. */ SCM scm_lease_c2scm_x(lease_t *lease) { lease_smob_t *lease_smob; lease_smob = scm_must_malloc(sizeof(lease_smob_t), "lease-make"); lease_smob->lease = lease; SCM_RETURN_NEWSMOB(lease_tag, lease_smob); } /* create a lease: this is called from within the scheme environment. */ static SCM scm_make_lease(SCM scm_ip_address, SCM scm_subnet_mask, SCM scm_lease_expiry, SCM scm_renew_time, SCM scm_rebind_time) { lease_t *lease; ip_addr_t ip_address, subnet_mask; uint32_t lease_expiry, renew_time, rebind_time; /* do assertions: all arguments can either be strings or inums */ SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), scm_ip_address, SCM_ARG1, "make-lease"); SCM_ASSERT(SCM_STRINGP(scm_subnet_mask)|SCM_INUMP(scm_subnet_mask), scm_subnet_mask, SCM_ARG2, "make-lease"); SCM_ASSERT(SCM_STRINGP(scm_lease_expiry)|SCM_INUMP(scm_lease_expiry), scm_lease_expiry, SCM_ARG3, "make-lease"); SCM_ASSERT(SCM_STRINGP(scm_renew_time)|SCM_INUMP(scm_renew_time), scm_renew_time, SCM_ARG4, "make-lease"); SCM_ASSERT(SCM_STRINGP(scm_rebind_time)|SCM_INUMP(scm_rebind_time), scm_rebind_time, SCM_ARG5, "make-lease"); /* if string change to number first. */ if(SCM_STRINGP(scm_ip_address)) { ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "make-lease")); } else { ip_address = scm_num2ulong(scm_ip_address, 1, "make-lease"); } if(SCM_STRINGP(scm_subnet_mask)) { subnet_mask = ntohl(scm_num2ulong(scm_inet_aton(scm_subnet_mask), 1, "make-lease")); } else { subnet_mask = scm_num2ulong(scm_subnet_mask, 1, "make-lease"); } if(SCM_STRINGP(scm_lease_expiry)) { lease_expiry = scm_num2ulong(scm_string_to_number(scm_lease_expiry, SCM_MAKINUM(10)), 10, "make-lease"); } else { lease_expiry = scm_num2ulong(scm_lease_expiry, 1, "make-lease"); } if(SCM_STRINGP(scm_renew_time)) { renew_time = scm_num2ulong(scm_string_to_number(scm_renew_time, SCM_MAKINUM(10)), 10, "make-lease"); } else { renew_time = scm_num2ulong(scm_renew_time, 1, "make-lease"); } if(SCM_STRINGP(scm_rebind_time)) { rebind_time = scm_num2ulong(scm_string_to_number(scm_rebind_time, SCM_MAKINUM(10)), 10, "make-lease"); } else { rebind_time = scm_num2ulong(scm_rebind_time, 1, "make-lease"); } lease = lease_create(ip_address, subnet_mask, lease_expiry, renew_time, rebind_time); return scm_lease_c2scm_x(lease); } /* setters. */ /* set ip address. */ static SCM scm_lease_set_ip_addr(SCM scm_lease, SCM scm_ip_address) { lease_smob_t *lease_smob; ip_addr_t ip_address; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-ip-addr"); SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), scm_ip_address, SCM_ARG2, "lease-set-ip-addr"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); if(SCM_STRINGP(scm_ip_address)) { ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "lease-set-ip-addr")); } else { ip_address = scm_num2ulong(scm_ip_address, 1, "lease-set-ip-addr"); } lease_set_address(lease_smob->lease, ip_address); return SCM_BOOL_T; } /* set subnet mask. */ static SCM scm_lease_set_subnet_mask(SCM scm_lease, SCM scm_subnet_mask) { lease_smob_t *lease_smob; ip_addr_t subnet_mask; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-subnet-mask"); SCM_ASSERT(SCM_STRINGP(scm_subnet_mask)|SCM_INUMP(scm_subnet_mask), scm_subnet_mask, SCM_ARG2, "lease-set-subnet-mask"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); if(SCM_STRINGP(scm_subnet_mask)) { subnet_mask = ntohl(scm_num2ulong(scm_inet_aton(scm_subnet_mask), 1, "lease-set-subnet-mask")); } else { subnet_mask = scm_num2ulong(scm_subnet_mask, 1, "lease-set-subnet-mask"); } lease_set_subnet_mask(lease_smob->lease, subnet_mask); return SCM_BOOL_T; } /* set renew time. */ static SCM scm_lease_set_renew(SCM scm_lease, SCM scm_renew_time) { lease_smob_t *lease_smob; uint32_t renew_time; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-renew-time"); SCM_ASSERT(SCM_STRINGP(scm_renew_time)|SCM_INUMP(scm_renew_time), scm_renew_time, SCM_ARG2, "lease-set-renew-time"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); if(SCM_STRINGP(scm_renew_time)) { renew_time = scm_num2ulong(scm_string_to_number(scm_renew_time, SCM_MAKINUM(10)), 10, "lease-set-renew-time"); } else { renew_time = scm_num2ulong(scm_renew_time, 1, "lease-set-renew-time"); } lease_set_renew(lease_smob->lease, renew_time); return SCM_BOOL_T; } /* set rebind time. */ static SCM scm_lease_set_rebind(SCM scm_lease, SCM scm_rebind_time) { lease_smob_t *lease_smob; uint32_t rebind_time; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-rebind-time"); SCM_ASSERT(SCM_STRINGP(scm_rebind_time)|SCM_INUMP(scm_rebind_time), scm_rebind_time, SCM_ARG2, "lease-set-rebind-time"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); if(SCM_STRINGP(scm_rebind_time)) { rebind_time = scm_num2ulong(scm_string_to_number(scm_rebind_time, SCM_MAKINUM(10)), 10, "lease-set-rebind-time"); } else { rebind_time = scm_num2ulong(scm_rebind_time, 1, "lease-set-rebind-time"); } lease_set_rebind(lease_smob->lease, rebind_time); return SCM_BOOL_T; } /* set the lease expiry. */ static SCM scm_lease_set_expiry(SCM scm_lease, SCM scm_expiry_time) { lease_smob_t *lease_smob; uint32_t expiry_time; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-expiry-time"); SCM_ASSERT(SCM_STRINGP(scm_expiry_time)|SCM_INUMP(scm_expiry_time), scm_expiry_time, SCM_ARG2, "lease-set-expiry-time"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); if(SCM_STRINGP(scm_expiry_time)) { expiry_time = scm_num2ulong(scm_string_to_number(scm_expiry_time, SCM_MAKINUM(10)), 10, "lease-set-expiry-time"); } else { expiry_time = scm_num2ulong(scm_expiry_time, 1, "lease-set-expiry-time"); } lease_set_expiry(lease_smob->lease, expiry_time); return SCM_BOOL_T; } /* set the lease options. */ static SCM scm_lease_set_options(SCM scm_lease, SCM scm_options) { lease_smob_t *lease_smob; list_t *options; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-set-options"); SCM_ASSERT(SCM_CONSP(scm_options), scm_options, SCM_ARG2, "lease-set-options"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); options = scm_dhcp_opt_list_to_c_list(scm_options); lease_set_options(lease_smob->lease, options); return SCM_BOOL_T; } /* accessors. */ /* get the ip address of the lease. */ static SCM scm_lease_get_ip_addr(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-ip-addr"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return SCM_MAKINUM(lease_get_address(lease_smob->lease)); } /* get the address of the lease in string form. */ static SCM scm_lease_get_ip_addr_string(SCM scm_lease) { SCM scm_ip_addr = scm_lease_get_ip_addr(scm_lease); return scm_number_to_string(scm_ip_addr, SCM_MAKINUM(10)); } /* get the subnet of the lease. */ static SCM scm_lease_get_subnet_mask(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-subnet"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return SCM_MAKINUM(lease_get_subnet_mask(lease_smob->lease)); } /* get the subnet of the lease in string format. */ static SCM scm_lease_get_subnet_mask_string(SCM scm_lease) { SCM scm_subnet_mask = scm_lease_get_subnet_mask(scm_lease); return scm_number_to_string(scm_subnet_mask, SCM_MAKINUM(10)); } /* get renew time. */ static SCM scm_lease_get_renew(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-renew"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return SCM_MAKINUM(lease_get_renew(lease_smob->lease)); } /* get rebind time. */ static SCM scm_lease_get_rebind(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-rebind"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return SCM_MAKINUM(lease_get_rebind(lease_smob->lease)); } /* get expiry time. */ static SCM scm_lease_get_expiry(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-ip-expiry"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return SCM_MAKINUM(lease_get_expiry(lease_smob->lease)); } /* return a list of dhcp options from the lease. */ static SCM scm_lease_get_options(SCM scm_lease) { lease_smob_t *lease_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(lease_tag, scm_lease), scm_lease, SCM_ARG1, "lease-get-options"); lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return scm_dhcp_opt_c_list_to_list(lease_smob->lease->options); } /* initialization routines for lease smob. */ void init_lease_smob(void) { lease_tag = scm_make_smob_type("lease", sizeof(lease_smob_t)); scm_set_smob_free(lease_tag, scm_lease_free); scm_set_smob_mark(lease_tag, scm_lease_mark); scm_set_smob_print(lease_tag, scm_lease_print); scm_c_define_gsubr("lease-make", 5, 0, 0, scm_make_lease); scm_c_define_gsubr("lease-set-ip-addr", 2, 0, 0, scm_lease_set_ip_addr); scm_c_define_gsubr("lease-set-subnet-mask", 2, 0, 0, scm_lease_set_subnet_mask); scm_c_define_gsubr("lease-set-renew-time", 2, 0, 0, scm_lease_set_renew); scm_c_define_gsubr("lease-set-rebind-time", 2, 0, 0, scm_lease_set_rebind); scm_c_define_gsubr("lease-set-expiry-time", 2, 0, 0, scm_lease_set_expiry); scm_c_define_gsubr("lease-set-options", 2, 0, 0, scm_lease_set_options); scm_c_define_gsubr("lease-get-ip-addr", 1, 0, 0, scm_lease_get_ip_addr); scm_c_define_gsubr("lease-get-ip-addr-string", 1, 0, 0, scm_lease_get_ip_addr_string); scm_c_define_gsubr("lease-get-subnet-mask", 1, 0, 0, scm_lease_get_subnet_mask); scm_c_define_gsubr("lease-get-subnet-mask-string", 1, 0, 0, scm_lease_get_subnet_mask_string); scm_c_define_gsubr("lease-get-renew-time", 1, 0, 0, scm_lease_get_renew); scm_c_define_gsubr("lease-get-rebind-time", 1, 0, 0, scm_lease_get_rebind); scm_c_define_gsubr("lease-get-expiry-time", 1, 0, 0, scm_lease_get_expiry); scm_c_define_gsubr("lease-get-options", 1, 0, 0, scm_lease_get_options); return; } /* get a copy of the lease from the scm lease: called from C code. */ lease_t *scm_c_get_lease(SCM scm_lease) { lease_smob_t *lease_smob; lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); return lease_copy(lease_smob->lease); } --- NEW FILE: dhcp-lease-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease-guile.h,v 1.1 2003/08/12 12:05:47 actmodern Exp $ * * Copyright 2003 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. * * client info smob * */ #ifndef DHCP_LEASE_GUILE_H #define DHCP_LEASE_GUILE_H typedef struct { lease_t *lease; } lease_smob_t; extern void init_lease_smob(void); extern lease_t *scm_c_get_lease(SCM scm_lease); extern SCM scm_lease_c2scm(lease_t *lease); extern SCM scm_lease_c2scm_x(lease_t *lease); #endif /* DHCP_LEASE_GUILE_H */ |
From: <act...@us...> - 2003-08-12 12:24:25
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22211 Modified Files: dhcp-option-guile.c dhcp-option-guile.h Log Message: cleaned up and added more functionality Index: dhcp-option-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-option-guile.c 10 Aug 2003 01:20:58 -0000 1.1 --- dhcp-option-guile.c 12 Aug 2003 12:06:59 -0000 1.2 *************** *** 39,42 **** --- 39,43 ---- * * * * * * * * * * */ + /* take an SCM dhcp tag and convert it to C dhcp tag. */ static int scm_to_dhcp_tag(SCM scm_tag, dhcp_opt_tag_t *tag) { *************** *** 104,107 **** --- 105,144 ---- } + /* take a list of options and return them as a cons. */ + SCM scm_dhcp_opt_c_list_to_list(list_t *options) + { + dhcp_opt_t *option; + SCM dhcp_opt_cons = SCM_EOL; + + list_rewind(options); + while((option = list_next(options)) != NULL) { + + dhcp_opt_cons = scm_cons(scm_dhcp_opt_c2scm(option), dhcp_opt_cons); + } + + return scm_reverse(dhcp_opt_cons); + } + + /* take a list of options and return them as a list. */ + list_t *scm_dhcp_opt_list_to_c_list(SCM options) + { + dhcp_opt_t *option; + list_t *list; + int i, list_length; + SCM scm_list_length; + + list = list_create(); + scm_list_length = scm_length(options); + list_length = scm_num2int(scm_list_length, SCM_ARG1, "scm_dhcp_opt_list_to_c_list"); + + for(i = 0; i < list_length; i++) { + + option = scm_dhcp_opt2c(scm_list_ref(options, SCM_MAKINUM(i))); + list_add_to_end(list, option); + } + + return list; + } + /* * * * * * * * * * * * dhcp option smob. * *************** *** 133,136 **** --- 170,184 ---- } + /* create a dhcp_opt smob from a C level dhcp option: this does not make a copy of the option */ + SCM scm_dhcp_opt_c2scm_x(dhcp_opt_t *dhcp_opt) + { + dhcp_opt_smob_t *dhcp_opt_smob; + + dhcp_opt_smob = scm_must_malloc(sizeof(dhcp_opt_smob_t), "dhcp-opt-make!"); + dhcp_opt_smob->dhcp_opt = dhcp_opt; + + SCM_RETURN_NEWSMOB(dhcp_opt_tag, dhcp_opt_smob); + } + /* create a dhcp_opt smob from a C level dhcp option */ SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt) *************** *** 146,149 **** --- 194,208 ---- } + dhcp_opt_t *scm_dhcp_opt2c(SCM scm_dhcp_opt) + { + dhcp_opt_smob_t *dhcp_opt_smob; + + SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt2c"); + dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); + + return dhcp_option_copy(dhcp_opt_smob->dhcp_opt); + } + + /* create a dhcp option: called from scheme code. */ static SCM scm_dhcp_opt_make(SCM scm_dhcp_tag, SCM scm_dhcp_opt_data) *************** *** 195,199 **** } ! return scm_dhcp_opt_c2scm(option); } --- 254,258 ---- } ! return scm_dhcp_opt_c2scm_x(option); } *************** *** 264,268 **** case DHCP_OPT_VAL_UINT16: ! return scm_str2symbol("dhcp-opt-val-type-int32"); case DHCP_OPT_VAL_INT16: --- 323,327 ---- case DHCP_OPT_VAL_UINT16: ! return scm_str2symbol("dhcp-opt-val-type-uint16"); case DHCP_OPT_VAL_INT16: *************** *** 318,321 **** --- 377,381 ---- /* setters. */ + /* FIXME: check if we're putting redundant code here, see above creation routines. */ /* set dhcp option data overwriting old data. */ static SCM scm_dhcp_opt_set_data(SCM scm_dhcp_opt, SCM scm_data) *************** *** 378,382 **** return SCM_BOOL_T; } - /* initialization routine for option smob. */ --- 438,441 ---- Index: dhcp-option-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-option-guile.h 10 Aug 2003 01:20:58 -0000 1.1 --- dhcp-option-guile.h 12 Aug 2003 12:06:59 -0000 1.2 *************** *** 32,38 **** } dhcp_opt_smob_t; - extern SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt); extern void init_dhcp_opt_smob(void); #endif /* DHCP_OPT_GUILE_H */ - --- 32,41 ---- } dhcp_opt_smob_t; extern void init_dhcp_opt_smob(void); + extern SCM scm_dhcp_opt_c_list_to_list(list_t *options); + extern SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt); + extern SCM scm_dhcp_opt_c2scm_x(dhcp_opt_t *dhcp_opt); + extern dhcp_opt_t *scm_dhcp_opt2c(SCM scm_dhcp_opt); + extern list_t *scm_dhcp_opt_list_to_c_list(SCM options); #endif /* DHCP_OPT_GUILE_H */ |
From: <act...@us...> - 2003-08-12 12:23:10
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22274 Modified Files: dhcp-server-guile.c dhcp-server-guile.h Log Message: integrated smobs back into server guile code Index: dhcp-server-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-guile.c 7 Aug 2003 01:14:27 -0000 1.5 --- dhcp-server-guile.c 12 Aug 2003 12:07:25 -0000 1.6 *************** *** 37,220 **** #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag, lease_tag, client_info_tag; ! SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; ! ! /* * * * * * * * * * * * * * * * * * * * ! * client info smob * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* mark a client_info: we don't need to do any marking. */ ! static SCM scm_client_info_mark(SCM scm_client_info) ! { ! return SCM_BOOL_F; ! } ! ! /* free a client_info. */ ! static size_t scm_client_info_free(SCM scm_client_info) ! { ! client_info_smob_t *client_info_smob; ! ! client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); ! client_info_destroy(client_info_smob->client_info); ! xfree(client_info_smob); ! ! return sizeof(client_info_smob); ! } ! ! /* print out a client info scm. */ ! static int scm_client_info_print(SCM scm_client_info, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<client_info>", port); ! return 1; ! } ! ! /* create a client info scm. */ ! static SCM scm_client_info_c_make(client_info_t *client_info) ! { ! client_info_smob_t *client_info_smob; ! client_info_t *new_client_info; ! ! new_client_info = client_info_copy(client_info); ! client_info_smob = scm_must_malloc(sizeof(client_info_smob_t), "client-info-make"); ! client_info_smob->client_info = new_client_info; ! ! SCM_RETURN_NEWSMOB(client_info_tag, client_info_smob); ! } ! ! /* initialization routines for client info smob. */ ! static void init_client_info_smob(void) ! { ! client_info_tag = scm_make_smob_type("client_info_smob", sizeof(client_info_smob_t)); ! ! scm_set_smob_free(client_info_tag, scm_client_info_free); ! scm_set_smob_mark(client_info_tag, scm_client_info_mark); ! scm_set_smob_print(client_info_tag, scm_client_info_print); ! ! return; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * lease smob * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* mark a lease: we don't need to do any marking. */ ! static SCM scm_lease_mark(SCM scm_lease) ! { ! return SCM_BOOL_F; ! } ! ! /* free a lease scm. */ ! static size_t scm_lease_free(SCM scm_lease) ! { ! lease_smob_t *lease; ! ! lease = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! lease_destroy(lease->lease); ! xfree(lease); ! ! return sizeof(lease_smob_t); ! } ! ! /* print out a lease scm. */ ! static int scm_lease_print(SCM scm_lease, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<lease>", port); ! return 1; ! } ! ! /* create a lease: this is called from within the scheme environment. */ ! static SCM scm_make_lease(SCM scm_ip_address, SCM scm_subnet_mask, SCM scm_lease_expiry, ! SCM scm_renew_time, SCM scm_rebind_time) ! { ! lease_smob_t *lease_smob; ! lease_t *lease; ! ip_addr_t ip_address, subnet_mask; ! uint32_t lease_expiry, renew_time, rebind_time; ! ! /* do assertions: all arguments can either be strings or inums */ ! ! SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), ! scm_ip_address, SCM_ARG1, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_subnet_mask)|SCM_INUMP(scm_subnet_mask), ! scm_subnet_mask, SCM_ARG2, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_lease_expiry)|SCM_INUMP(scm_lease_expiry), ! scm_lease_expiry, SCM_ARG3, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_renew_time)|SCM_INUMP(scm_renew_time), ! scm_renew_time, SCM_ARG4, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_rebind_time)|SCM_INUMP(scm_rebind_time), ! scm_rebind_time, SCM_ARG5, "make-lease"); ! ! /* if string change to number first. */ ! ! if(SCM_STRINGP(scm_ip_address)) { ! ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "make-lease")); ! } else { ! ip_address = scm_num2ulong(scm_ip_address, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_subnet_mask)) { ! subnet_mask = ntohl(scm_num2ulong(scm_inet_aton(scm_subnet_mask), 1, "make-lease")); ! } else { ! subnet_mask = scm_num2ulong(scm_subnet_mask, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_lease_expiry)) { ! lease_expiry = scm_num2ulong(scm_inet_aton(scm_lease_expiry), 1, "make-lease"); ! } else { ! lease_expiry = scm_num2ulong(scm_lease_expiry, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_renew_time)) { ! renew_time = scm_num2ulong(scm_inet_aton(scm_renew_time), 1, "make-lease"); ! } else { ! renew_time = scm_num2ulong(scm_renew_time, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_rebind_time)) { ! rebind_time = scm_num2ulong(scm_inet_aton(scm_rebind_time), 1, "make-lease"); ! } else { ! rebind_time = scm_num2ulong(scm_rebind_time, 1, "make-lease"); ! } ! ! lease = lease_create(ip_address, subnet_mask, lease_expiry, renew_time, rebind_time); ! lease_smob = scm_must_malloc(sizeof(lease_smob_t), "lease-make"); ! lease_smob->lease = lease; ! ! SCM_RETURN_NEWSMOB(lease_tag, lease); ! } ! ! /* create an SCM lease: this is called from the C code: a copy is ! made so garbage collection doesn't clubber our copy */ ! static SCM scm_c_make_lease(lease_t *lease) ! { ! return scm_make_lease(SCM_MAKINUM(lease_get_address(lease)), SCM_MAKINUM(lease_get_subnet_mask(lease)), ! SCM_MAKINUM(lease_get_expiry(lease)), SCM_MAKINUM(lease_get_renew(lease)), ! SCM_MAKINUM(lease_get_rebind(lease))); ! } ! ! /* get a copy of the lease from the scm lease: caled from C code. */ ! static lease_t * scm_c_get_lease(SCM scm_lease) ! { ! lease_smob_t *lease_smob; ! ! lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! return lease_copy(lease_smob->lease); ! } ! ! /* initialization routines for lease smob. */ ! static void init_lease_smob(void) ! { ! lease_tag = scm_make_smob_type("lease", sizeof(lease_smob_t)); ! ! scm_set_smob_free(lease_tag, scm_lease_free); ! scm_set_smob_mark(lease_tag, scm_lease_mark); ! scm_set_smob_print(lease_tag, scm_lease_print); ! return; ! } /* * * * * * * * * * * * * * * * * * * * --- 37,46 ---- #include "dhcp-server-guile.h" ! #include "dhcp-lease-guile.h" ! #include "dhcp-client-info-guile.h" ! #include "dhcp-option-guile.h" ! static scm_t_bits server_control_tag; ! SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; /* * * * * * * * * * * * * * * * * * * * *************** *** 394,398 **** SCM scm_return; ! scm_lease = scm_c_make_lease(lease); scm_return = scm_call_1(scm_variable_ref(lease_acquire), scm_lease); --- 220,224 ---- SCM scm_return; ! scm_lease = scm_lease_c2scm(lease); scm_return = scm_call_1(scm_variable_ref(lease_acquire), scm_lease); *************** *** 410,414 **** SCM scm_return; ! scm_lease = scm_c_make_lease(lease); scm_return = scm_call_1(scm_variable_ref(lease_release), scm_lease); --- 236,240 ---- SCM scm_return; ! scm_lease = scm_lease_c2scm(lease); scm_return = scm_call_1(scm_variable_ref(lease_release), scm_lease); Index: dhcp-server-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-guile.h 7 Aug 2003 01:14:27 -0000 1.5 --- dhcp-server-guile.h 12 Aug 2003 12:07:25 -0000 1.6 *************** *** 30,41 **** } server_control_smob_t; - typedef struct { - lease_t *lease; - } lease_smob_t; - - typedef struct { - client_info_t *client_info; - } client_info_smob_t; - /* prototypes. */ --- 30,33 ---- |
From: <act...@us...> - 2003-08-12 12:15:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22032 Modified Files: dhcp-guile-util.c Log Message: added more utilities Index: dhcp-guile-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-guile-util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-guile-util.c 10 Aug 2003 01:21:33 -0000 1.2 --- dhcp-guile-util.c 12 Aug 2003 12:06:17 -0000 1.3 *************** *** 119,121 **** return scm_string_list; } - --- 119,120 ---- |
From: <act...@us...> - 2003-08-12 12:11:59
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv23091 Modified Files: README Log Message: more in README Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** README 26 Jul 2003 23:50:43 -0000 1.14 --- README 12 Aug 2003 12:11:56 -0000 1.15 *************** *** 57,61 **** When submitting patches please try to keep your programming style ! consistent with ours. This shouldn't be too hard. Installing: --- 57,63 ---- When submitting patches please try to keep your programming style ! consistent with ours. This shouldn't be too hard. If you don't ! have the inclination to do this, we'd prefer receiving an ugly ! patch as opposed receiving none. Installing: *************** *** 67,85 **** ------- ! Visit: http://lists.sourceforge.net/lists/listinfo/dhcp-agent-users ! To subscribe to the dhcp-agent-users list. ! ! Also: http://lists.sourceforge.net/lists/listinfo/dhcp-agent-announce ! For announcements. ! For filing a support request or bug report please consider ! visiting dhcp-agent's page at sourceforge and using the ! applicable forum: http://www.sourceforge.net/projects/dhcp-agent/ --- 69,89 ---- ------- ! For user discussion please use the user list: http://lists.sourceforge.net/lists/listinfo/dhcp-agent-users ! For announcements use the announcement list: http://lists.sourceforge.net/lists/listinfo/dhcp-agent-announce ! If you'd like to discuss development of the suite, use the ! development mailing list: ! http://lists.sourceforge.net/lists/listinfo/dhcp-agent-devel ! ! If you have a bug report, please consider mailing either the user ! or development mailing list. ! ! You can also use the trackers on the sourceforge project page: http://www.sourceforge.net/projects/dhcp-agent/ *************** *** 87,92 **** Although I do try to reply to mails sent to me personaly, please know that you are more likely to receive a response from others ! on the list, or receive better support from the support forums. I ! am slower than a greater collective of users. In addition to this you can always check the ERRATA file which is --- 91,96 ---- Although I do try to reply to mails sent to me personaly, please know that you are more likely to receive a response from others ! on the list, or receive better support from the trackers. I am ! slower than a greater collective of users. In addition to this you can always check the ERRATA file which is *************** *** 101,105 **** I announce major updates to the ERRATA file on the ! dhcp-agent-users list Documentation --- 105,109 ---- I announce major updates to the ERRATA file on the ! dhcp-agent-users list. Documentation *************** *** 131,134 **** --- 135,147 ---- a warm fuzzy feeling. + Note to Package Maintainers: + ---------------------------- + + If you are maintaining a package of dhcp-agent for a distribution + please, and I do mean *please*, consider giving back any patches + which fix bugs, or make this software more portable. If this is + too much work for you, consider letting us know where we can find + your package so we can keep an eye on it. + Contributing ------------ *************** *** 137,140 **** --- 150,164 ---- contributing back patches, comments, bug reports, or becoming involved with its development. + + If you live in the Greater Toronto Area in Ontario, Canada and + have extra hardware to spare I can usually make use of it for the + project. Ram, drives, boards, and network appliances are useful + to the project. + + If you want to contribute in cash, please know the project + currently does not need it. Instead consider contributing to the + Free Software Foundation (FSF) at: + + https://agia.fsf.org/mp/order.py?make-donation=1 -- |
From: <act...@us...> - 2003-08-12 12:09:45
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22295 Modified Files: Makefile.am Log Message: now building with new smobs Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Makefile.am 10 Aug 2003 01:23:38 -0000 1.36 --- Makefile.am 12 Aug 2003 12:07:42 -0000 1.37 *************** *** 24,28 **** dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h \ ! dhcp-server-client-info.h dhcp-option-guile.h libdhcputil_la_SOURCES = dhcp-util.c \ --- 24,29 ---- dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h \ ! dhcp-server-client-info.h dhcp-option-guile.h dhcp-client-info-guile.h \ ! dhcp-lease-guile.h libdhcputil_la_SOURCES = dhcp-util.c \ *************** *** 82,86 **** dhcp-option-guile.c \ dhcp-server-lease-manager.c \ ! dhcp-server-client-info.c dhcp_client_LDADD = -ldhcputil ${GUILE_LIB} --- 83,89 ---- dhcp-option-guile.c \ dhcp-server-lease-manager.c \ ! dhcp-server-client-info.c \ ! dhcp-client-info-guile.c \ ! dhcp-lease-guile.c dhcp_client_LDADD = -ldhcputil ${GUILE_LIB} |
From: <act...@us...> - 2003-08-12 12:05:23
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv21919 Added Files: dhcp-client-info-guile.c dhcp-client-info-guile.h Log Message: client info smob moved to seperate source; now more complete --- NEW FILE: dhcp-client-info-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-info-guile.c,v 1.1 2003/08/12 12:05:20 actmodern Exp $ * * Copyright 2003 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. * * client info smob * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-guile-util.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-server-client-info.h" #include "dhcp-client-info-guile.h" #include "dhcp-limits.h" static scm_t_bits client_info_tag; /* mark a client_info: we don't need to do any marking. */ static SCM scm_client_info_mark(SCM scm_client_info) { return SCM_BOOL_F; } /* free a client_info. */ static size_t scm_client_info_free(SCM scm_client_info) { client_info_smob_t *client_info_smob; client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); client_info_destroy(client_info_smob->client_info); xfree(client_info_smob); return sizeof(client_info_smob); } /* print out a client info scm. */ static int scm_client_info_print(SCM scm_client_info, SCM port, scm_print_state *pstate) { scm_puts("#<client_info>", port); return 1; } /* create a client info scm. */ SCM scm_client_info_c_make(client_info_t *client_info) { client_info_smob_t *client_info_smob; client_info_t *new_client_info; new_client_info = client_info_copy(client_info); client_info_smob = scm_must_malloc(sizeof(client_info_smob_t), "client-info-make"); client_info_smob->client_info = new_client_info; SCM_RETURN_NEWSMOB(client_info_tag, client_info_smob); } /* get the hostname. */ static SCM scm_client_info_get_hostname(SCM scm_client_info) { client_info_smob_t *client_info_smob; const char *hostname; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_hostname"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); hostname = client_info_get_hostname(client_info_smob->client_info); if(hostname == NULL) return SCM_BOOL_F; else return scm_makfrom0str(hostname); } /* get the client_id. */ static SCM scm_client_info_get_client_id(SCM scm_client_info) { client_info_smob_t *client_info_smob; const char *client_id; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_get_client_id_"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); client_id = client_info_get_client_id(client_info_smob->client_info); if(client_id == NULL) return SCM_BOOL_F; else return scm_makfrom0str(client_id); } /* get the chaddr. */ static SCM scm_client_info_get_chaddr(SCM scm_client_info) { client_info_smob_t *client_info_smob; char *chaddr_str; eth_addr_t chaddr; SCM scm_chaddr; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_chaddr"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); chaddr = client_info_get_chaddr(client_info_smob->client_info); chaddr_str = eth_addr_to_string(chaddr); scm_chaddr = scm_makfrom0str(chaddr_str); xfree(chaddr_str); return scm_chaddr; } /* get the giaddr. */ static SCM scm_client_info_get_giaddr(SCM scm_client_info) { client_info_smob_t *client_info_smob; char *giaddr_str; ip_addr_t giaddr; SCM scm_giaddr; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_giaddr"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); giaddr = client_info_get_giaddr(client_info_smob->client_info); giaddr_str = ip_addr_to_string(giaddr); scm_giaddr = scm_makfrom0str(giaddr_str); xfree(giaddr_str); return scm_giaddr; } /* get the max message size. */ static SCM scm_client_info_get_max_message_size(SCM scm_client_info) { client_info_smob_t *client_info_smob; uint16_t max_message_size; SCM scm_max_message_size; SCM_ASSERT(SCM_SMOB_PREDICATE(client_info_tag, scm_client_info), scm_client_info, SCM_ARG1, "scm_client_info_get_max_message_size"); client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); max_message_size = client_info_get_max_message_size(client_info_smob->client_info); scm_max_message_size = SCM_MAKINUM(max_message_size); return scm_number_to_string(scm_max_message_size, SCM_MAKINUM(10)); } /* initialization routines for client info smob. */ void init_client_info_smob(void) { client_info_tag = scm_make_smob_type("client_info_smob", sizeof(client_info_smob_t)); scm_set_smob_free(client_info_tag, scm_client_info_free); scm_set_smob_mark(client_info_tag, scm_client_info_mark); scm_set_smob_print(client_info_tag, scm_client_info_print); scm_c_define_gsubr("dhcp-client-info-get-hostname", 1, 0, 0, scm_client_info_get_hostname); scm_c_define_gsubr("dhcp-client-info-get-client-id", 1, 0, 0, scm_client_info_get_client_id); scm_c_define_gsubr("dhcp-client-info-get-chaddr", 1, 0, 0, scm_client_info_get_chaddr); scm_c_define_gsubr("dhcp-client-info-get-giaddr", 1, 0, 0, scm_client_info_get_giaddr); scm_c_define_gsubr("dhcp-client-info-get-max-message-size", 1, 0, 0, scm_client_info_get_max_message_size); return; } --- NEW FILE: dhcp-client-info-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-info-guile.h,v 1.1 2003/08/12 12:05:20 actmodern Exp $ * * Copyright 2003 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. * * client info smob * */ #ifndef DHCP_CLIENT_INFO_GUILE_H #define DHCP_CLIENT_INFO_GUILE_H typedef struct { client_info_t *client_info; } client_info_smob_t; extern void init_client_info_smob(void); extern SCM scm_client_info_c_make(client_info_t *client_info); #endif /* DHCP_CLIENT_INFO_GUILE_H */ |
From: <act...@us...> - 2003-08-10 01:23:41
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19366 Modified Files: Makefile.am Log Message: added option smob to server Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Makefile.am 7 Aug 2003 01:14:27 -0000 1.35 --- Makefile.am 10 Aug 2003 01:23:38 -0000 1.36 *************** *** 24,28 **** dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h \ ! dhcp-server-client-info.h libdhcputil_la_SOURCES = dhcp-util.c \ --- 24,28 ---- dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h \ ! dhcp-server-client-info.h dhcp-option-guile.h libdhcputil_la_SOURCES = dhcp-util.c \ *************** *** 80,83 **** --- 80,84 ---- dhcp-server-guile.c \ dhcp-guile-util.c \ + dhcp-option-guile.c \ dhcp-server-lease-manager.c \ dhcp-server-client-info.c |
From: <act...@us...> - 2003-08-10 01:23:14
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19315 Modified Files: dhcp-option.c dhcp-option.h Log Message: added routine to get by type by tag Index: dhcp-option.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-option.c 5 Aug 2003 04:57:38 -0000 1.7 --- dhcp-option.c 10 Aug 2003 01:23:11 -0000 1.8 *************** *** 1365,1368 **** --- 1365,1369 ---- } + /* get type. */ dhcp_opt_type_t dhcp_opt_get_type(dhcp_opt_t *opt) { *************** *** 1370,1378 **** } ! dhcp_opt_type_t dhcp_opt_get_val_type(dhcp_opt_t *opt) { return DHCP_OPT_GET_VAL_TYPE(opt); } dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt) { --- 1371,1381 ---- } ! /* get val type. */ ! dhcp_opt_val_type_t dhcp_opt_get_val_type(dhcp_opt_t *opt) { return DHCP_OPT_GET_VAL_TYPE(opt); } + /* get tag. */ dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt) { *************** *** 1514,1516 **** --- 1517,1530 ---- return; + } + + /* return option data type by tag. */ + int dhcp_opt_get_type_by_tag(dhcp_opt_tag_t tag) + { + + if(tag <= MAX_OPTIONS_HANDLED) { + return dhcp_opt_attr[tag].type; + } + + return DHCP_OPT_UNKNOWN; } Index: dhcp-option.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-option.h 5 Aug 2003 04:57:38 -0000 1.8 --- dhcp-option.h 10 Aug 2003 01:23:11 -0000 1.9 *************** *** 42,49 **** --- 42,51 ---- extern dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt); extern dhcp_opt_type_t dhcp_opt_get_type(dhcp_opt_t *opt); + extern dhcp_opt_val_type_t dhcp_opt_get_val_type(dhcp_opt_t *opt); extern void dhcp_opt_destroy(dhcp_opt_t *opt); extern void dhcp_opt_destroy_option_list(list_t *list); extern dhcp_opt_t *dhcp_option_copy(dhcp_opt_t *option); extern list_t *dhcp_option_copy_list(list_t *option_list); + extern int dhcp_opt_get_type_by_tag(dhcp_opt_tag_t tag); extern dhcp_opt_t *dhcp_opt_create_message_type(uint8_t message_type); *************** *** 53,64 **** extern void dhcp_option_prepend(dhcp_opt_t *orig, dhcp_opt_t *data); - /* constants. */ /* opt type. */ ! #define DHCP_OPT_LIST 1 ! #define DHCP_OPT_ATOM 2 ! #define DHCP_OPT_STRING 3 ! #define DHCP_OPT_ARRAY 4 /* opt val type. */ --- 55,62 ---- extern void dhcp_option_prepend(dhcp_opt_t *orig, dhcp_opt_t *data); /* constants. */ /* opt type. */ ! enum opt_type { DHCP_OPT_UNKNOWN = 0, DHCP_OPT_LIST, DHCP_OPT_ATOM, DHCP_OPT_STRING, DHCP_OPT_ARRAY }; /* opt val type. */ |
From: <act...@us...> - 2003-08-10 01:21:35
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19018 Modified Files: dhcp-guile-util.c dhcp-guile-util.h Log Message: added more utilities Index: dhcp-guile-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-guile-util.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-guile-util.c 5 Aug 2003 04:49:09 -0000 1.1 --- dhcp-guile-util.c 10 Aug 2003 01:21:33 -0000 1.2 *************** *** 21,25 **** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * guile utility routines which guile should be offering but isn't :| * */ --- 21,25 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * guile utility routines. * */ *************** *** 29,32 **** --- 29,36 ---- #include "dhcp-guile-util.h" + /* * * * * * * * * * * * * * * * * * * * * + * routines guile should be offering but isn't :| * + * * * * * * * * * * * * * * * * * * * * */ + char *x_scm_symbol2newstr(SCM symbol) { *************** *** 54,55 **** --- 58,121 ---- return newstr; } + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * + * converting between our own native types and guile. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + /* take a string list from guile and turn it into a native list. */ + list_t *x_scm_guile_string_list_to_list(SCM scm_list) + { + list_t *list; + int i, list_length; + char *str; + SCM scm_list_length, scm_string; + + list = list_create(); + + scm_list_length = scm_length(scm_list); + list_length = scm_num2int(scm_list_length, SCM_ARG1, "x_scm_guile_string_list_to_list"); + + for(i = 0; i < list_length; i++) { + scm_string = scm_list_ref(scm_list, SCM_MAKINUM(i)); + + if(!(SCM_STRINGP(scm_string))) { + list_destroy(list, xfree); + return NULL; + } + + str = x_scm_string2newstr(scm_string); + list_add_to_end(list, str); + + } + + return list; + } + + /* take a string which contains atoms which are comma delimited, and create an SCM list of strings */ + SCM x_scm_comma_delimited_string_to_scm_list(const char *string_val) + { + char *str_copy, *cptr, *ptr; + SCM scm_string_list = SCM_EOL; + + str_copy = xstrdup(string_val); + + ptr = str_copy; + for(cptr = str_copy; ptr; ptr = strchr(cptr, ',')) { + + *ptr = 0; + ptr++; + + while(*cptr == ' ') + cptr++; + + if(*cptr == 0) + return SCM_EOL; /* munged string list. */ + + scm_string_list = scm_cons(scm_makfrom0str(cptr), scm_string_list); + } + + scm_string_list = scm_reverse(scm_string_list); + + return scm_string_list; + } + Index: dhcp-guile-util.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-guile-util.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-guile-util.h 5 Aug 2003 04:49:09 -0000 1.1 --- dhcp-guile-util.h 10 Aug 2003 01:21:33 -0000 1.2 *************** *** 30,33 **** --- 30,35 ---- extern char *x_scm_symbol2newstr(SCM symbol); extern char *x_scm_string2newstr(SCM string); + extern list_t *x_scm_guile_string_list_to_list(SCM scm_list); + extern SCM x_scm_comma_delimited_string_to_scm_list(const char *string_val); #endif /* DHCP_GUILE_UTIL_H */ |
From: <act...@us...> - 2003-08-10 01:21:03
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv18912 Added Files: dhcp-option-guile.h dhcp-option-guile.c Log Message: added new dhcp option SMOB --- NEW FILE: dhcp-option-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.h,v 1.1 2003/08/10 01:20:58 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. * * dhcp option SMOB * */ #ifndef DHCP_OPT_GUILE_H #define DHCP_OPT_GUILE_H typedef struct { dhcp_opt_t *dhcp_opt; } dhcp_opt_smob_t; extern SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt); extern void init_dhcp_opt_smob(void); #endif /* DHCP_OPT_GUILE_H */ --- NEW FILE: dhcp-option-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-guile.c,v 1.1 2003/08/10 01:20:58 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. * * dhcp option SMOB * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-guile-util.h" #include "dhcp-option-guile.h" #include "dhcp-limits.h" static scm_t_bits dhcp_opt_tag; /* * * * * * * * * * * * utility routines. * * * * * * * * * * * */ static int scm_to_dhcp_tag(SCM scm_tag, dhcp_opt_tag_t *tag) { int inum; SCM_ASSERT(SCM_STRINGP(scm_tag)|SCM_INUMP(scm_tag), scm_tag, SCM_ARG1, "dhcp-opt-make"); if(!(SCM_STRINGP(scm_tag))) { inum = scm_num2int(scm_string_to_number(scm_tag, SCM_MAKINUM(10)), 10, "scm_to_dhcp_tag"); } else { /* FIXME: guile doesn't support C99 types yet. when it * does create a function to convert specifically to * dhcp_opt_tag_t which is actually a uint8_t */ inum = scm_num2int(scm_tag, 10, "scm_to_dhcp_tag"); } /* make sure its not greater than what we're prepared to * handle, and that it's not equal to 0 (pad) or less than * zero. */ if(inum > MAX_OPTIONS_HANDLED || inum <= 0) { return 1; } else { *tag = (uint8_t)inum; return 0; } } /* take a single datum option and turn it into a dhcp option. */ static dhcp_opt_t *scm_dhcp_opt_string_to_option(dhcp_opt_tag_t tag, SCM scm_dhcp_opt_data) { dhcp_opt_t *option; char *user_string; list_t *user_string_list; /* just call the user string creation function. */ user_string = x_scm_string2newstr(scm_dhcp_opt_data); user_string_list = list_create(); list_add(user_string_list, user_string); option = dhcp_opt_create_from_user_string(tag, user_string); list_destroy(user_string_list, xfree); return option; } /* take a list datum option and turn it into a dhcp option. */ static dhcp_opt_t *scm_dhcp_opt_list_to_option(dhcp_opt_tag_t tag, SCM scm_dhcp_opt_data) { dhcp_opt_t *option; list_t *string_list; /* just call the user string creation function. */ string_list = x_scm_guile_string_list_to_list(scm_dhcp_opt_data); option = dhcp_opt_create_from_user_string(tag, string_list); list_destroy(string_list, xfree); return option; } /* * * * * * * * * * * * dhcp option smob. * * * * * * * * * * * */ /* mark a dhcp_opt smob: we don't need to do any marking. */ static SCM scm_dhcp_opt_mark(SCM scm_dhcp_opt) { return SCM_BOOL_F; } /* free a dhcp_opt. */ static size_t scm_dhcp_opt_free(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); dhcp_opt_destroy(dhcp_opt_smob->dhcp_opt); xfree(dhcp_opt_smob); return sizeof(dhcp_opt_smob); } /* print out a dhcp opt smob. */ static int scm_dhcp_opt_print(SCM scm_dhcp_opt, SCM port, scm_print_state *pstate) { scm_puts("#<dhcp_opt>", port); return 1; } /* create a dhcp_opt smob from a C level dhcp option */ SCM scm_dhcp_opt_c2scm(dhcp_opt_t *dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; dhcp_opt_t *new_dhcp_opt; new_dhcp_opt = dhcp_option_copy(dhcp_opt); dhcp_opt_smob = scm_must_malloc(sizeof(dhcp_opt_smob_t), "dhcp-opt-make"); dhcp_opt_smob->dhcp_opt = new_dhcp_opt; SCM_RETURN_NEWSMOB(dhcp_opt_tag, dhcp_opt_smob); } /* create a dhcp option: called from scheme code. */ static SCM scm_dhcp_opt_make(SCM scm_dhcp_tag, SCM scm_dhcp_opt_data) { dhcp_opt_tag_t tag; dhcp_opt_t *option; SCM_ASSERT(SCM_STRINGP(scm_dhcp_tag)|SCM_INUMP(scm_dhcp_tag), scm_dhcp_tag, SCM_ARG1, "dhcp-opt-make"); SCM_ASSERT(SCM_CONSP(scm_dhcp_opt_data)|SCM_STRINGP(scm_dhcp_opt_data), scm_dhcp_tag, SCM_ARG1, "dhcp-opt-make"); if(scm_to_dhcp_tag(scm_dhcp_tag, &tag)) { scm_error(scm_str2symbol("illegal-dhcp-tag"), "scm_dhcp_opt_make", "dhcp tag unhandled or out of range", SCM_EOL, SCM_EOL); } switch(dhcp_opt_get_type_by_tag(tag)) { case DHCP_OPT_LIST: if(!(SCM_CONSP(scm_dhcp_tag))) scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "dhcp data in atom form while list expected", SCM_EOL, SCM_EOL); option = scm_dhcp_opt_list_to_option(tag, scm_dhcp_opt_data); break; case DHCP_OPT_ATOM: case DHCP_OPT_STRING: case DHCP_OPT_ARRAY: if(!(SCM_CONSP(scm_dhcp_tag))) scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "dhcp data in list form while atom expected", SCM_EOL, SCM_EOL); option = scm_dhcp_opt_string_to_option(tag, scm_dhcp_opt_data); break; default: scm_error(scm_str2symbol("unknown-option-data-type"), "scm_dhcp_opt_make", "unable to convert dhcp option data. this is a bug. report me.", SCM_EOL, SCM_EOL); } if(option == NULL) { scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "could not create option from data passed", SCM_EOL, SCM_EOL); } return scm_dhcp_opt_c2scm(option); } /* accessors. */ static SCM scm_dhcp_opt_get_tag(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_get_tag"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); return SCM_MAKINUM(dhcp_opt_get_tag(dhcp_opt_smob->dhcp_opt)); } static SCM scm_dhcp_opt_get_name(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_get_name"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); return scm_makfrom0str(dhcp_opt_get_user_string(dhcp_opt_smob->dhcp_opt)); } static SCM scm_dhcp_opt_get_type(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; dhcp_opt_type_t dhcp_type; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_get_type"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); dhcp_type = dhcp_opt_get_type(dhcp_opt_smob->dhcp_opt); switch(dhcp_type) { case DHCP_OPT_LIST: return scm_str2symbol("dhcp-opt-type-list"); case DHCP_OPT_STRING: case DHCP_OPT_ATOM: case DHCP_OPT_ARRAY: return scm_str2symbol("dhcp-opt-type-atom"); default: return scm_str2symbol("dhcp-opt-type-unknown"); } } static SCM scm_dhcp_opt_get_val_type(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; dhcp_opt_val_type_t dhcp_type; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_val_type"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); dhcp_type = dhcp_opt_get_val_type(dhcp_opt_smob->dhcp_opt); switch(dhcp_type) { case DHCP_OPT_VAL_UINT32: return scm_str2symbol("dhcp-opt-val-type-uint32"); case DHCP_OPT_VAL_INT32: return scm_str2symbol("dhcp-opt-val-type-int32"); case DHCP_OPT_VAL_UINT16: return scm_str2symbol("dhcp-opt-val-type-int32"); case DHCP_OPT_VAL_INT16: return scm_str2symbol("dhcp-opt-val-type-int16"); case DHCP_OPT_VAL_UINT8: return scm_str2symbol("dhcp-opt-val-type-uint8"); case DHCP_OPT_VAL_INT8: return scm_str2symbol("dhcp-opt-val-type-int8"); case DHCP_OPT_VAL_ADDRESS: return scm_str2symbol("dhcp-opt-val-type-address"); case DHCP_OPT_VAL_ADDRESS_PAIR: return scm_str2symbol("dhcp-opt-val-type-address-pair"); default: return scm_str2symbol("dhcp-opt-val-type-unknown"); } } /* get data from a dhcp option. */ static SCM scm_dhcp_opt_get_data(SCM scm_dhcp_opt) { dhcp_opt_smob_t *dhcp_opt_smob; char *string_val; SCM scm_string_val; dhcp_opt_type_t dhcp_type; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_get_data"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); dhcp_type = dhcp_opt_get_type(dhcp_opt_smob->dhcp_opt); string_val = dhcp_opt_get_user_string(dhcp_opt_smob->dhcp_opt); switch(dhcp_type) { case DHCP_OPT_LIST: /* string val is comma delimited list, convert here. */ scm_string_val = x_scm_comma_delimited_string_to_scm_list(string_val); default: scm_string_val = scm_makfrom0str(string_val); } xfree(string_val); return scm_string_val; } /* setters. */ /* set dhcp option data overwriting old data. */ static SCM scm_dhcp_opt_set_data(SCM scm_dhcp_opt, SCM scm_data) { dhcp_opt_smob_t *dhcp_opt_smob; dhcp_opt_type_t dhcp_type; list_t *strings; dhcp_opt_tag_t tag; dhcp_opt_t *new_option; SCM_ASSERT(SCM_SMOB_PREDICATE(dhcp_opt_tag, scm_dhcp_opt), scm_dhcp_opt, SCM_ARG1, "scm_dhcp_opt_set_data"); SCM_ASSERT(SCM_CONSP(scm_data)|SCM_STRINGP(scm_data), scm_data, SCM_ARG2, "scm_dhcp_opt_set_data"); dhcp_opt_smob = (dhcp_opt_smob_t *)SCM_SMOB_DATA(scm_dhcp_opt); dhcp_type = dhcp_opt_get_type(dhcp_opt_smob->dhcp_opt); switch(dhcp_type) { case DHCP_OPT_LIST: if(!SCM_CONSP(scm_data)) { scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "expected list and received atom", SCM_EOL, SCM_EOL); } strings = x_scm_guile_string_list_to_list(scm_data); break; case DHCP_OPT_ATOM: case DHCP_OPT_ARRAY: case DHCP_OPT_STRING: if(!SCM_STRINGP(scm_data)) { scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "expected atom and received list", SCM_EOL, SCM_EOL); } strings = list_create(); list_add(strings, x_scm_string2newstr(scm_data)); break; default: scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "cannot set data since option has unknown type", SCM_EOL, SCM_EOL); } tag = dhcp_opt_get_tag(dhcp_opt_smob->dhcp_opt); new_option = dhcp_opt_create_from_user_string(tag, strings); list_destroy(strings, xfree); if(new_option == NULL) { scm_error(scm_str2symbol("bad-option-data"), "scm_dhcp_opt_make", "could not create option from data passed", SCM_EOL, SCM_EOL); } dhcp_opt_destroy(dhcp_opt_smob->dhcp_opt); dhcp_opt_smob->dhcp_opt = new_option; return SCM_BOOL_T; } /* initialization routine for option smob. */ void init_dhcp_opt_smob(void) { dhcp_opt_tag = scm_make_smob_type("dhcp_opt_smob", sizeof(dhcp_opt_smob_t)); /* set smob functions .*/ scm_set_smob_free(dhcp_opt_tag, scm_dhcp_opt_free); scm_set_smob_mark(dhcp_opt_tag, scm_dhcp_opt_mark); scm_set_smob_print(dhcp_opt_tag, scm_dhcp_opt_print); /* bind the subroutines. */ scm_c_define_gsubr("dhcp-opt-make", 2, 0, 0, scm_dhcp_opt_make); scm_c_define_gsubr("dhcp-opt-get-tag", 1, 0, 0, scm_dhcp_opt_get_tag); scm_c_define_gsubr("dhcp-opt-get-name", 1, 0, 0, scm_dhcp_opt_get_name); scm_c_define_gsubr("dhcp-opt-get-type", 1, 0, 0, scm_dhcp_opt_get_type); scm_c_define_gsubr("dhcp-opt-get-val-type", 1, 0, 0, scm_dhcp_opt_get_val_type); scm_c_define_gsubr("dhcp-opt-get-data", 1, 0, 0, scm_dhcp_opt_get_data); scm_c_define_gsubr("dhcp-opt-set-data!", 2, 0, 0, scm_dhcp_opt_set_data); return; } |
From: <act...@us...> - 2003-08-07 01:14:30
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv28241/src Modified Files: Makefile.am dhcp-server-guile.c dhcp-server-guile.h dhcp-server-lease-manager.c dhcp-server-lease-manager.h dhcp-server-states.c dhcp-server.c Added Files: dhcp-server-client-info.c dhcp-server-client-info.h Log Message: added new client_info datum to hold information on client --- NEW FILE: dhcp-server-client-info.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-client-info.c,v 1.1 2003/08/07 01:14:27 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. * * The client info datum allows us to pack all the information * from the client in one place just by looking at the incoming * dhcp packet. * */ #define MODULE_NAME "dhcp-server-client-info" #include "dhcp-local.h" #include "dhcp-limits.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-server-client-info.h" /******************************* * utilities * *******************************/ /* given a pointer to a max message size, which may be NULL, do * the logic to find the right max message size. */ static uint16_t get_max_message_size(dhcp_server_control_t *sc, uint16_t *max_message_size_ptr) { uint16_t configured_max_message_size; /* get the configured max message size: we use this in the * absence of a max message size from the client, and if it * is smaller than our mtu. */ configured_max_message_size = server_conf_get_max_message_size(sc->server_conf); /* we get a null pointer if the client never passed us a max message. */ if(max_message_size_ptr == NULL) /* none passed. */ { if(configured_max_message_size < rawnet_get_mtu(sc->rawnet)) return configured_max_message_size; else return rawnet_get_mtu(sc->rawnet); } else if(*max_message_size_ptr > rawnet_get_mtu(sc->rawnet)) /* use mtu if the max message size is greater. */ return rawnet_get_mtu(sc->rawnet); /* otherwise use the max message size. */ else return *max_message_size_ptr; } /******************************* * create/destroy * *******************************/ /* create a client info from an incoming dhcp packet. */ client_info_t *client_info_create(dhcp_server_control_t *sc, dhcp_obj *dhcp) { client_info_t *client_info; char *hostname = NULL; uint8_t *chaddr; dhcp_opt_t *client_id = NULL; dhcp_opt_t *opt; uint16_t *max_message_size = NULL; client_info = xcalloc(sizeof(client_info_t)); client_info->giaddr = dhcp_get_giaddr(dhcp); chaddr = dhcp_get_chaddr(dhcp); memcpy(&client_info->chaddr, chaddr, ETH_ADDR_LEN); dhcp_reset_option_seek(dhcp); while((opt = dhcp_get_next_option(dhcp)) != NULL) { switch(dhcp_opt_get_tag(opt)) { case TAG_DHCP_CLIENT_ID: client_id = opt; break; case TAG_DHCP_MAX_DHCP_SIZE: max_message_size = dhcp_opt_get_host_data(opt); break; case TAG_DHCP_HOST_NAME: hostname = dhcp_opt_get_host_data(opt); break; default: break; } } if(client_id != NULL) client_info->client_id = dhcp_opt_get_user_string(client_id); client_info->max_message_size = get_max_message_size(sc, max_message_size); if(hostname != NULL) { client_info->hostname = xstrdup(hostname); } return client_info; } /* destroy a client info. */ void client_info_destroy(client_info_t *client_info) { if(client_info->client_id != NULL) xfree(client_info->client_id); if(client_info->hostname != NULL) xfree(client_info->hostname); xfree(client_info); return; } client_info_t *client_info_copy(client_info_t *client_info) { client_info_t *new_client_info; new_client_info = xcalloc(sizeof(client_info_t)); if(client_info->client_id != NULL) new_client_info->client_id = xstrdup(client_info->client_id); if(client_info->hostname != NULL) new_client_info->hostname = xstrdup(client_info->hostname); new_client_info->giaddr = client_info->giaddr; new_client_info->chaddr = client_info->chaddr; return new_client_info; } /******************************* * accessors * *******************************/ const char *client_info_get_hostname(client_info_t *client_info) { return client_info->hostname; } const char *client_info_get_client_id(client_info_t *client_info) { return client_info->client_id; } eth_addr_t client_info_get_chaddr(client_info_t *client_info) { return client_info->chaddr; } ip_addr_t client_info_get_giaddr(client_info_t *client_info) { return client_info->giaddr; } uint16_t client_info_get_max_message_size(client_info_t *client_info) { return client_info->max_message_size; } --- NEW FILE: dhcp-server-client-info.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-client-info.h,v 1.1 2003/08/07 01:14:27 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. * * These are the individual server state functions, * along with their utility routines. * */ #ifndef DHCP_SERVER_CLIENT_INFO_H #define DHCP_SERVER_CLIENT_INFO_H typedef struct { char *hostname; /* hostname provided by client if any. */ char *client_id; /* client id provided by client if any. */ eth_addr_t chaddr; /* the chaddr provided by the client. */ ip_addr_t giaddr; /* ip address of relay agent. */ uint16_t max_message_size; /* max message size if any. */ } client_info_t; extern client_info_t *client_info_create(dhcp_server_control_t *sc, dhcp_obj *dhcp); extern void client_info_destroy(client_info_t *client_info); extern client_info_t *client_info_copy(client_info_t *client_info); extern const char *client_info_get_hostname(client_info_t *client_info); extern const char *client_info_get_client_id(client_info_t *client_info); extern eth_addr_t client_info_get_chaddr(client_info_t *client_info); extern ip_addr_t client_info_get_giaddr(client_info_t *client_info); extern uint16_t client_info_get_max_message_size(client_info_t *client_info); #endif /* DHCP_SERVER_CLIENT_INFO_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Makefile.am 5 Aug 2003 04:49:09 -0000 1.34 --- Makefile.am 7 Aug 2003 01:14:27 -0000 1.35 *************** *** 23,27 **** dhcp-client-guile.h dhcp-sniff-defaults.h dhcp-client-defaults.h dhcp-lease.h \ dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ ! dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h libdhcputil_la_SOURCES = dhcp-util.c \ --- 23,28 ---- dhcp-client-guile.h dhcp-sniff-defaults.h dhcp-client-defaults.h dhcp-lease.h \ dhcp-server.h dhcp-server-guile.h dhcp-server-conf.h dhcp-server-defaults.h \ ! dhcp-server-guile.h dhcp-server-lease-manager.h dhcp-guile-util.h \ ! dhcp-server-client-info.h libdhcputil_la_SOURCES = dhcp-util.c \ *************** *** 79,83 **** dhcp-server-guile.c \ dhcp-guile-util.c \ ! dhcp-server-lease-manager.c dhcp_client_LDADD = -ldhcputil ${GUILE_LIB} --- 80,85 ---- dhcp-server-guile.c \ dhcp-guile-util.c \ ! dhcp-server-lease-manager.c \ ! dhcp-server-client-info.c dhcp_client_LDADD = -ldhcputil ${GUILE_LIB} Index: dhcp-server-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-server-guile.c 6 Aug 2003 04:29:16 -0000 1.4 --- dhcp-server-guile.c 7 Aug 2003 01:14:27 -0000 1.5 *************** *** 33,67 **** #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-guile-util.h" #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag, lease_tag; SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; /* * * * * * * * * * * * * * * * * * * * ! * misc utilities * * * * * * * * * * * * * * * * * * * * */ ! /* make a lease data list to pass to the user: fixme, make it a record. */ ! static SCM make_lease_data_list(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id) { ! SCM data_list; ! char *eth_addr_string, *giaddr_string, *client_id_string; ! eth_addr_string = eth_addr_to_string(mac_addr); ! giaddr_string = ip_addr_to_string(giaddr); ! client_id_string = dhcp_opt_get_user_string(client_id); ! data_list = SCM_EOL; ! data_list = scm_cons(scm_makfrom0str(client_id_string), data_list); ! data_list = scm_cons(scm_makfrom0str(giaddr_string), data_list); ! data_list = scm_cons(scm_makfrom0str(eth_addr_string), data_list); ! data_list = scm_cons(scm_makfrom0str(hostname), data_list); ! xfree(eth_addr_string); ! xfree(giaddr_string); ! xfree(client_id_string); ! return data_list; } --- 33,95 ---- #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-server-client-info.h" #include "dhcp-guile-util.h" #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag, lease_tag, client_info_tag; SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; /* * * * * * * * * * * * * * * * * * * * ! * client info smob * * * * * * * * * * * * * * * * * * * * */ ! /* mark a client_info: we don't need to do any marking. */ ! static SCM scm_client_info_mark(SCM scm_client_info) { ! return SCM_BOOL_F; ! } ! /* free a client_info. */ ! static size_t scm_client_info_free(SCM scm_client_info) ! { ! client_info_smob_t *client_info_smob; ! client_info_smob = (client_info_smob_t *)SCM_SMOB_DATA(scm_client_info); ! client_info_destroy(client_info_smob->client_info); ! xfree(client_info_smob); ! return sizeof(client_info_smob); ! } ! /* print out a client info scm. */ ! static int scm_client_info_print(SCM scm_client_info, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<client_info>", port); ! return 1; ! } ! ! /* create a client info scm. */ ! static SCM scm_client_info_c_make(client_info_t *client_info) ! { ! client_info_smob_t *client_info_smob; ! client_info_t *new_client_info; ! ! new_client_info = client_info_copy(client_info); ! client_info_smob = scm_must_malloc(sizeof(client_info_smob_t), "client-info-make"); ! client_info_smob->client_info = new_client_info; ! ! SCM_RETURN_NEWSMOB(client_info_tag, client_info_smob); ! } ! ! /* initialization routines for client info smob. */ ! static void init_client_info_smob(void) ! { ! client_info_tag = scm_make_smob_type("client_info_smob", sizeof(client_info_smob_t)); ! ! scm_set_smob_free(client_info_tag, scm_client_info_free); ! scm_set_smob_mark(client_info_tag, scm_client_info_mark); ! scm_set_smob_print(client_info_tag, scm_client_info_print); ! ! return; } *************** *** 178,182 **** } ! /* initialization routines for lease SMOB. */ static void init_lease_smob(void) { --- 206,210 ---- } ! /* initialization routines for lease smob. */ static void init_lease_smob(void) { *************** *** 291,294 **** --- 319,325 ---- init_lease_smob(); + /* initialize client info smob. */ + init_client_info_smob(); + /* bind symbols to top level so that the user defined script can hook into them. */ *************** *** 330,341 **** /* ask if any leases are available. */ ! lease_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! SCM data_list, scm_lease; lease_t *lease; ! data_list = make_lease_data_list(hostname, mac_addr, giaddr, client_id); ! scm_lease = scm_call_1(scm_variable_ref(lease_available), data_list); lease = scm_c_get_lease(scm_lease); --- 361,371 ---- /* ask if any leases are available. */ ! lease_t *dhcp_guile_lease_available(client_info_t *client_info) { ! SCM scm_client_info, scm_lease; lease_t *lease; ! scm_client_info = scm_client_info_c_make(client_info); ! scm_lease = scm_call_1(scm_variable_ref(lease_available), scm_client_info); lease = scm_c_get_lease(scm_lease); *************** *** 344,355 **** /* lookup a lease: lookup a lease. */ ! lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! SCM data_list, scm_lease; lease_t *lease; ! data_list = make_lease_data_list(hostname, mac_addr, giaddr, client_id); ! scm_lease = scm_call_1(scm_variable_ref(lease_lookup), data_list); lease = scm_c_get_lease(scm_lease); --- 374,386 ---- /* lookup a lease: lookup a lease. */ ! lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, client_info_t *client_info) { ! SCM scm_client_info, scm_lease, scm_ip_addr; lease_t *lease; ! scm_client_info = scm_client_info_c_make(client_info); ! scm_ip_addr = SCM_MAKINUM(ip_addr); ! ! scm_lease = scm_call_2(scm_variable_ref(lease_lookup), scm_ip_addr, scm_client_info); lease = scm_c_get_lease(scm_lease); Index: dhcp-server-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-server-guile.h 5 Aug 2003 04:59:32 -0000 1.4 --- dhcp-server-guile.h 7 Aug 2003 01:14:27 -0000 1.5 *************** *** 26,45 **** #define DHCP_SERVER_GUILE_H ! typedef struct client_control_smob { dhcp_server_control_t *sc; } server_control_smob_t; ! typedef struct lease_smob { lease_t *lease; } lease_smob_t; /* prototypes. */ extern void dhcp_guile_init(dhcp_server_control_t *sc); extern int dhcp_guile_initialize_leases(void); ! extern lease_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); extern int dhcp_guile_acquire_lease(lease_t *definition); extern int dhcp_guile_release_lease(lease_t *definition); --- 26,47 ---- #define DHCP_SERVER_GUILE_H ! typedef struct { dhcp_server_control_t *sc; } server_control_smob_t; ! typedef struct { lease_t *lease; } lease_smob_t; + typedef struct { + client_info_t *client_info; + } client_info_smob_t; + /* prototypes. */ extern void dhcp_guile_init(dhcp_server_control_t *sc); extern int dhcp_guile_initialize_leases(void); ! extern lease_t *dhcp_guile_lease_available(client_info_t *client_info); ! extern lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, client_info_t *client_info); extern int dhcp_guile_acquire_lease(lease_t *definition); extern int dhcp_guile_release_lease(lease_t *definition); Index: dhcp-server-lease-manager.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-lease-manager.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-server-lease-manager.c 5 Aug 2003 05:00:00 -0000 1.2 --- dhcp-server-lease-manager.c 7 Aug 2003 01:14:27 -0000 1.3 *************** *** 31,34 **** --- 31,35 ---- #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-server-client-info.h" #include "dhcp-lease.h" #include "dhcp-server-lease-manager.h" *************** *** 40,55 **** } ! lease_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return dhcp_guile_lease_available(hostname, mac_addr, ! giaddr, client_id); } ! lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return dhcp_guile_lookup_lease(ip_addr, hostname, mac_addr, ! giaddr, client_id); } --- 41,52 ---- } ! lease_t *lease_manager_lease_available(client_info_t *client_info) { ! return dhcp_guile_lease_available(client_info); } ! lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, client_info_t *client_info) { ! return dhcp_guile_lookup_lease(ip_addr, client_info); } Index: dhcp-server-lease-manager.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-lease-manager.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-server-lease-manager.h 5 Aug 2003 05:00:00 -0000 1.2 --- dhcp-server-lease-manager.h 7 Aug 2003 01:14:27 -0000 1.3 *************** *** 26,33 **** extern int initialize_lease_manager(void); ! extern lease_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); extern int lease_manager_acquire_lease(lease_t *lease); extern int lease_manager_release_lease(lease_t *lease); --- 26,31 ---- extern int initialize_lease_manager(void); ! extern lease_t *lease_manager_lease_available(client_info_t *client_info); ! extern lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, client_info_t *client_info); extern int lease_manager_acquire_lease(lease_t *lease); extern int lease_manager_release_lease(lease_t *lease); Index: dhcp-server-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-states.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-server-states.c 6 Aug 2003 04:29:39 -0000 1.6 --- dhcp-server-states.c 7 Aug 2003 01:14:27 -0000 1.7 *************** *** 35,41 **** #include "dhcp-lease.h" - #include "dhcp-server-lease-manager.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" /******************************* --- 35,42 ---- #include "dhcp-lease.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-server-client-info.h" + #include "dhcp-server-lease-manager.h" /******************************* *************** *** 65,96 **** } - /* given a pointer to a max message size, which may be NULL, do - * the logic to find the right max message size. */ - uint16_t get_max_message_size(dhcp_server_control_t *sc, uint16_t *max_message_size_ptr) - { - uint16_t configured_max_message_size; - - /* get the configured max message size: we use this in the - * absence of a max message size from the client, and if it - * is smaller than our mtu. */ - - configured_max_message_size = server_conf_get_max_message_size(sc->server_conf); - - /* we get a null pointer if the client never passed us a max message. */ - if(max_message_size_ptr == NULL) /* none passed. */ { - - if(configured_max_message_size < rawnet_get_mtu(sc->rawnet)) - return configured_max_message_size; - else - return rawnet_get_mtu(sc->rawnet); - } - else if(*max_message_size_ptr > rawnet_get_mtu(sc->rawnet)) /* use mtu if the max message size is greater. */ - return rawnet_get_mtu(sc->rawnet); - - /* otherwise use the max message size. */ - else - return *max_message_size_ptr; - } - /* utility routine to get a list of options from a lease. */ static list_t *create_options_from_lease(dhcp_server_control_t *sc, lease_t *lease) --- 66,69 ---- *************** *** 187,242 **** int server_handle_discover(dhcp_server_control_t *sc) { ! char *hostname = NULL; ! eth_addr_t mac_addr; ! uint8_t *chaddr; ! ip_addr_t giaddr; ! dhcp_opt_t *client_id = NULL; ! dhcp_opt_t *opt; lease_t *lease; - uint16_t *max_message_size = NULL; dhcp_obj *dhcp = sc->rawnet->dhcp_p; ! /* a client wants to discover possible leases. get the ! * information we need to pass to the lease manager and ask ! * the manager if any leases are available for it. */ ! ! giaddr = dhcp_get_giaddr(dhcp); ! ! chaddr = dhcp_get_chaddr(dhcp); ! memcpy(&mac_addr, chaddr, ETH_ADDR_LEN); ! ! dhcp_reset_option_seek(dhcp); ! while((opt = dhcp_get_next_option(dhcp)) != NULL) { ! ! switch(dhcp_opt_get_tag(opt)) { ! ! case TAG_DHCP_CLIENT_ID: ! client_id = opt; ! break; ! ! case TAG_DHCP_MAX_DHCP_SIZE: ! max_message_size = dhcp_opt_get_host_data(opt); ! break; ! ! case TAG_DHCP_HOST_NAME: ! hostname = dhcp_opt_get_host_data(opt); ! break; ! ! default: ! break; ! } ! } ! lease = lease_manager_lease_available(hostname, mac_addr, ! giaddr, client_id); if(lease == NULL) ! return STATE_LISTEN; /* we have no possible leases. */ /* otherwise we do have a lease, send out an OFFER. */ ! if(server_do_offer(sc, lease, get_max_message_size(sc, max_message_size), mac_addr, dhcp_get_xid(dhcp))) return STATE_SHUTDOWN; return STATE_LISTEN; } --- 160,186 ---- int server_handle_discover(dhcp_server_control_t *sc) { ! client_info_t *client_info; lease_t *lease; dhcp_obj *dhcp = sc->rawnet->dhcp_p; ! /* get the information from the dhcp packet which describes the client. */ ! client_info = client_info_create(sc, dhcp); ! /* check for lease availability for this client. */ ! lease = lease_manager_lease_available(client_info); if(lease == NULL) ! return STATE_LISTEN; /* we have no possible leases: we drop the packet. */ /* otherwise we do have a lease, send out an OFFER. */ ! if(server_do_offer(sc, lease, client_info_get_max_message_size(client_info), client_info_get_chaddr(client_info), dhcp_get_xid(dhcp))) return STATE_SHUTDOWN; + /* clean up. */ + client_info_destroy(client_info); + lease_destroy(lease); + + /* and return to listen state after we're done. */ return STATE_LISTEN; } *************** *** 244,247 **** --- 188,192 ---- int server_handle_request(dhcp_server_control_t *sc) { + /* a client is requesting a lease, find out from the lease * manager if we can give it the lease. */ Index: dhcp-server.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-server.c 5 Aug 2003 05:01:02 -0000 1.11 --- dhcp-server.c 7 Aug 2003 01:14:27 -0000 1.12 *************** *** 32,35 **** --- 32,36 ---- #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-server-client-info.h" #include "dhcp-guile-util.h" #include "dhcp-server-guile.h" |
From: <act...@us...> - 2003-08-07 01:14:30
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv28241 Modified Files: TODO Log Message: added new client_info datum to hold information on client Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** TODO 19 Jul 2003 02:28:05 -0000 1.22 --- TODO 7 Aug 2003 01:14:27 -0000 1.23 *************** *** 57,58 **** --- 57,62 ---- -- make the hostname option settable via the command line. + + -- use client identifier as well as xid to track DHCP operations. + + -- dhcp_is_type is too expensive. use dhcp_get_type |
From: <act...@us...> - 2003-08-07 01:14:30
|
Update of /cvsroot/dhcp-agent/dhcp-agent/doc In directory sc8-pr-cvs1:/tmp/cvs-serv28241/doc Modified Files: part-4.texi Log Message: added new client_info datum to hold information on client Index: part-4.texi =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/doc/part-4.texi,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** part-4.texi 22 Jul 2003 20:18:53 -0000 1.1 --- part-4.texi 7 Aug 2003 01:14:27 -0000 1.2 *************** *** 3,22 **** @cindex Extensions Intro ! [TODO] ! @node Extending dhcp-client ! @chapter Extending dhcp-client ! @cindex Extending dhcp-client ! dhcp-client uses guile (GNU's Ubiquitous Intelligent Language for ! Extensions) to extend itself. Extensions can currently be written for ! handling DHCP options during system configuration time. Essentially, ! the extension script defines how the client configures the local ! system according to the DHCP options passed. The rest of this section assumes you are familiar with the Scheme programming language. If you are not familiar with the Scheme ! programming language then you cannot extend the client to configure ! options it is not programmed to handle. @section The Client Sysconf Script --- 3,48 ---- @cindex Extensions Intro ! If you've come this far in the manual you are probably either just ! curious or want more from your DHCP suite. Extensions can currently be ! written for both the client and the server. ! dhcp-agent uses guile (GNU's Ubiquitous Intelligent Language for ! Extensions) to extend itself. guile is an embeddable Scheme ! interpreter which ships its core as a C library. ! dhcp-agent has the scheme intrepreter embedded both in its client and ! server. ! ! The client will allow you to rewrite its system configuration ! script. This will allow you to handle more options the way you want to ! handle them, and do whatever system specific settings you want to ! do. The default script shipped with the client will perform basic ! network configuration only -- typically what the average user wants. ! ! The server allows you to extend it's lease backend. This allows you to ! assign leases based on the alogrithms you see fit. It also allows you ! to place the information anywhere you want. The default backend script ! will keep all lease information in memory and maintain a journal on ! disk as it assigns the leases. This lease information can be specified ! via the server configuration directives mentioned earlier. ! ! A typical client extension is defining more option handlers for your ! system. ! ! A typical server extesnions is backending the server into a database, ! or a directory service. ! ! When writing extensions you will be able to access the user defined ! configuration. It is important not to ignore them. This will allow ! your extensions to be useful to other people, and allow you to make ! configuration changes and have them honored by your own extensions. The rest of this section assumes you are familiar with the Scheme programming language. If you are not familiar with the Scheme ! programming language then you cannot write extensions for dhcp-agent. ! ! @node Extending dhcp-client ! @chapter Extending dhcp-client ! @cindex Extending dhcp-client @section The Client Sysconf Script |
From: <act...@us...> - 2003-08-06 04:30:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent/conf/dhcp-server In directory sc8-pr-cvs1:/tmp/cvs-serv5034/conf/dhcp-server Modified Files: lease.conf.example Log Message: added max-message-size variable Index: lease.conf.example =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/conf/dhcp-server/lease.conf.example,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** lease.conf.example 28 Jul 2003 00:32:30 -0000 1.7 --- lease.conf.example 6 Aug 2003 04:30:16 -0000 1.8 *************** *** 13,16 **** --- 13,24 ---- set default-rebind-percent = 90; + # Max message size settings. + # + # Recommended size in RFC791 (572 - ip header length - udp header length) + # This is only used if the client does not explicitly provide + # one, and this size is smaller than the interface mtu. + + set max-message-size = 544; + # set the signal/socket polling to 5 second intervals. # this is reasonable for today's systems. |
From: <act...@us...> - 2003-08-06 04:29:42
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv4909 Modified Files: dhcp-server-states.c Log Message: added logic code for picking max message size in responses Index: dhcp-server-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-states.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-states.c 5 Aug 2003 05:01:02 -0000 1.5 --- dhcp-server-states.c 6 Aug 2003 04:29:39 -0000 1.6 *************** *** 69,75 **** uint16_t get_max_message_size(dhcp_server_control_t *sc, uint16_t *max_message_size_ptr) { ! if(max_message_size_ptr == NULL) /* none passed. */ ! return rawnet_get_mtu(sc->rawnet); /* use the mtu then. */ else if(*max_message_size_ptr > rawnet_get_mtu(sc->rawnet)) /* use mtu if the max message size is greater. */ return rawnet_get_mtu(sc->rawnet); --- 69,88 ---- uint16_t get_max_message_size(dhcp_server_control_t *sc, uint16_t *max_message_size_ptr) { ! uint16_t configured_max_message_size; ! ! /* get the configured max message size: we use this in the ! * absence of a max message size from the client, and if it ! * is smaller than our mtu. */ + configured_max_message_size = server_conf_get_max_message_size(sc->server_conf); + + /* we get a null pointer if the client never passed us a max message. */ + if(max_message_size_ptr == NULL) /* none passed. */ { + + if(configured_max_message_size < rawnet_get_mtu(sc->rawnet)) + return configured_max_message_size; + else + return rawnet_get_mtu(sc->rawnet); + } else if(*max_message_size_ptr > rawnet_get_mtu(sc->rawnet)) /* use mtu if the max message size is greater. */ return rawnet_get_mtu(sc->rawnet); *************** *** 117,124 **** /* construct and send an offer. */ ! static int server_do_offer(dhcp_server_control_t *sc, lease_t *lease, uint16_t *max_message_size_ptr, eth_addr_t eth_addr, uint32_t xid) { - uint16_t max_message_size = get_max_message_size(sc, max_message_size_ptr); list_t *options; dhcp_opt_t *option; --- 130,136 ---- /* construct and send an offer. */ ! static int server_do_offer(dhcp_server_control_t *sc, lease_t *lease, uint16_t max_message_size, eth_addr_t eth_addr, uint32_t xid) { list_t *options; dhcp_opt_t *option; *************** *** 140,146 **** * build a unicast packet and unicast. */ - /* remove me. and do something with me. */ - max_message_size = 0; - if(dhcp_get_giaddr(dhcp) != 0) { --- 152,155 ---- *************** *** 227,231 **** /* otherwise we do have a lease, send out an OFFER. */ ! if(server_do_offer(sc, lease, max_message_size, mac_addr, dhcp_get_xid(dhcp))) return STATE_SHUTDOWN; --- 236,240 ---- /* otherwise we do have a lease, send out an OFFER. */ ! if(server_do_offer(sc, lease, get_max_message_size(sc, max_message_size), mac_addr, dhcp_get_xid(dhcp))) return STATE_SHUTDOWN; |
From: <act...@us...> - 2003-08-06 04:29:18
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv4882 Modified Files: dhcp-server-guile.c Log Message: fixed type in server-guile Index: dhcp-server-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-server-guile.c 5 Aug 2003 04:59:32 -0000 1.3 --- dhcp-server-guile.c 6 Aug 2003 04:29:16 -0000 1.4 *************** *** 23,27 **** * Glue between dhcp-server and guile. * - * */ --- 23,26 ---- *************** *** 44,47 **** --- 43,47 ---- * * * * * * * * * * * * * * * * * * * */ + /* make a lease data list to pass to the user: fixme, make it a record. */ static SCM make_lease_data_list(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id) { *************** *** 178,182 **** } ! /* initialization routines for server control SMOB. */ static void init_lease_smob(void) { --- 178,182 ---- } ! /* initialization routines for lease SMOB. */ static void init_lease_smob(void) { |
From: <act...@us...> - 2003-08-06 04:28:36
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv4803 Modified Files: dhcp-server-conf.c dhcp-server-conf.h dhcp-server-defaults.h Log Message: added max-message-size variable Index: dhcp-server-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-server-conf.c 27 Jul 2003 03:16:41 -0000 1.12 --- dhcp-server-conf.c 6 Aug 2003 04:28:33 -0000 1.13 *************** *** 41,44 **** --- 41,45 ---- "default-renew-percent", "default-rebind-percent", + "max-message-size", "poll-timeout" }; *************** *** 47,50 **** --- 48,52 ---- SERVER_VAR_RENEW_PERCENT, SERVER_VAR_REBIND_PERCENT, + SERVER_VAR_MAX_MESSAGE_SIZE, SERVER_VAR_POLL_TIMEOUT, }; *************** *** 210,213 **** --- 212,220 ---- } + uint16_t server_conf_get_max_message_size(server_conf_t *sc) + { + return sc->max_message_size; + } + /* * * * * * * * * * * *************** *** 250,253 **** --- 257,272 ---- } + /* set variable utility routines. */ + static int server_conf_set_uint16(server_conf_t *server_conf, uint16_t *var, const char *var_value) + { + if(!is_unsigned_numeric(var_value)) { + ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value); + return 1; + } + + sscanf(var_value, "%"SCNu16, var); + return 0; + } + /* set variable. */ static int server_conf_set_variable(server_conf_t *server_conf, arg_symbol_t var_symbol, const char *var_value) *************** *** 255,297 **** switch(var_symbol) { ! case SERVER_VAR_RENEW_PERCENT: ! ! if(!is_unsigned_numeric(var_value)) { ! ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value); ! return 1; ! } ! sscanf(var_value, "%"SCNu16, &server_conf->default_renew_percent); if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */ FATAL_MESSAGE("value specified for default-renew-percent is an illegal percent (over 100)"); } ! ! break; case SERVER_VAR_REBIND_PERCENT: ! if(!is_unsigned_numeric(var_value)) { ! ERROR_MESSAGE("value not unsigned numeric as expected : %s", var_value); ! return 1; ! } ! ! sscanf(var_value, "%"SCNu16, &server_conf->default_rebind_percent); ! if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */ ! FATAL_MESSAGE("value specified for default-rebind-percent is an illegal percent (over 100)"); } ! ! break; case SERVER_VAR_POLL_TIMEOUT: ! ! if(!is_unsigned_numeric(var_value)) { ! ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value); ! return 1; ! } ! ! sscanf(var_value, "%"SCNu16, &server_conf->poll_timeout); ! break; default: --- 274,298 ---- switch(var_symbol) { ! case SERVER_VAR_MAX_MESSAGE_SIZE: ! return server_conf_set_uint16(server_conf, &server_conf->max_message_size, var_value); ! case SERVER_VAR_RENEW_PERCENT: + server_conf_set_uint16(server_conf, &server_conf->default_renew_percent, var_value); if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */ FATAL_MESSAGE("value specified for default-renew-percent is an illegal percent (over 100)"); } ! return 0; case SERVER_VAR_REBIND_PERCENT: ! server_conf_set_uint16(server_conf, &server_conf->default_rebind_percent, var_value); if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */ ! FATAL_MESSAGE("value specified for default-renew-percent is an illegal percent (over 100)"); } ! return 0; case SERVER_VAR_POLL_TIMEOUT: ! return server_conf_set_uint16(server_conf, &server_conf->poll_timeout, var_value); default: *************** *** 300,305 **** return 1; } - - return 0; } --- 301,304 ---- *************** *** 699,705 **** /* set defaults. */ ! sc->default_rebind_percent = SERVER_DEFAULT_REBIND_PERCENT; ! sc->default_renew_percent = SERVER_DEFAULT_RENEW_PERCENT; ! sc->poll_timeout = SERVER_DEFAULT_POLL_TIMEOUT; sc->assume_interface_subnet = 1; /* default is yes. */ --- 698,706 ---- /* set defaults. */ ! sc->default_rebind_percent = SERVER_DEFAULT_REBIND_PERCENT; ! sc->default_renew_percent = SERVER_DEFAULT_RENEW_PERCENT; ! sc->poll_timeout = SERVER_DEFAULT_POLL_TIMEOUT; ! sc->max_message_size = SERVER_DEFAULT_MAX_MESSAGE_SIZE; ! sc->assume_interface_subnet = 1; /* default is yes. */ Index: dhcp-server-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-server-conf.h 27 Jul 2003 03:13:48 -0000 1.9 --- dhcp-server-conf.h 6 Aug 2003 04:28:33 -0000 1.10 *************** *** 38,41 **** --- 38,42 ---- uint16_t default_renew_percent; /* percent of expiry to assign as renew time. */ uint16_t poll_timeout; /* poll timeout -- used in server event processing. */ + uint16_t max_message_size; /* default max message size. */ uint8_t assume_interface_subnet; /* assume the interface has the correct local subnet configured. */ *************** *** 48,52 **** enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT, SERVER_VAR_POLL_TIMEOUT, ! SERVER_VAR_ASSUME_LOCAL_SUBNET_FROM_INTERFACE }; enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_HOSTNAME_LEASE, DIRECTIVE_MAC_LEASE, DIRECTIVE_OPTION, DIRECTIVE_LOCAL_SUBNET, DIRECTIVE_SUBNET, DIRECTIVE_ENABLE }; --- 49,53 ---- enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT, SERVER_VAR_POLL_TIMEOUT, ! SERVER_VAR_MAX_MESSAGE_SIZE, SERVER_VAR_ASSUME_LOCAL_SUBNET_FROM_INTERFACE }; enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_HOSTNAME_LEASE, DIRECTIVE_MAC_LEASE, DIRECTIVE_OPTION, DIRECTIVE_LOCAL_SUBNET, DIRECTIVE_SUBNET, DIRECTIVE_ENABLE }; *************** *** 59,62 **** --- 60,64 ---- extern uint16_t server_conf_get_poll_timeout(server_conf_t *sc); + extern uint16_t server_conf_get_max_message_size(server_conf_t *sc); #endif /* DHCP_SERVER_CONF_H */ Index: dhcp-server-defaults.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-defaults.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-server-defaults.h 15 Jul 2003 10:56:34 -0000 1.2 --- dhcp-server-defaults.h 6 Aug 2003 04:28:33 -0000 1.3 *************** *** 45,47 **** --- 45,50 ---- #define SERVER_DEFAULT_POLL_TIMEOUT 5 + /* recommended size in RFC791 (572 - ip header length - udp header length) */ + #define SERVER_DEFAULT_MAX_MESSAGE_SIZE 544 + #endif /* DHCP_SERVER_DEFAULTS_H */ |
From: <act...@us...> - 2003-08-05 05:01:05
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26777/src Modified Files: dhcp-server-control.c dhcp-server-states.c dhcp-server.c Log Message: more work on server. wrote initial offer code and hooked it into the lease manager Index: dhcp-server-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-control.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-server-control.c 26 Jul 2003 23:49:11 -0000 1.6 --- dhcp-server-control.c 5 Aug 2003 05:01:02 -0000 1.7 *************** *** 43,46 **** --- 43,47 ---- dhcp_server_control->server_conf = server_conf; + sport = rawnet_port_for_service("bootpc", "udp"); dport = rawnet_port_for_service("bootps", "udp"); Index: dhcp-server-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-states.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-server-states.c 20 Jul 2003 05:52:31 -0000 1.4 --- dhcp-server-states.c 5 Aug 2003 05:01:02 -0000 1.5 *************** *** 32,40 **** #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" - /******************************* * utilities * --- 32,42 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" + #include "dhcp-lease.h" + #include "dhcp-server-lease-manager.h" #include "dhcp-server-conf.h" #include "dhcp-server.h" /******************************* * utilities * *************** *** 63,66 **** --- 65,258 ---- } + /* given a pointer to a max message size, which may be NULL, do + * the logic to find the right max message size. */ + uint16_t get_max_message_size(dhcp_server_control_t *sc, uint16_t *max_message_size_ptr) + { + if(max_message_size_ptr == NULL) /* none passed. */ + return rawnet_get_mtu(sc->rawnet); /* use the mtu then. */ + + else if(*max_message_size_ptr > rawnet_get_mtu(sc->rawnet)) /* use mtu if the max message size is greater. */ + return rawnet_get_mtu(sc->rawnet); + + /* otherwise use the max message size. */ + else + return *max_message_size_ptr; + } + + /* utility routine to get a list of options from a lease. */ + static list_t *create_options_from_lease(dhcp_server_control_t *sc, lease_t *lease) + { + list_t *options; + dhcp_opt_t *option; + uint32_t period; + ip_addr_t subnet; + + options = dhcp_option_copy_list(lease_get_options(lease)); /* copy out the user defined options. */ + + /* append the renew, rebind, and expiry options. */ + + period = lease_get_rebind(lease); + option = dhcp_opt_create_from_internal_data(TAG_DHCP_REBINDING_TIME, &period, sizeof(uint32_t)); + list_add(options, option); + + period = lease_get_renew(lease); + option = dhcp_opt_create_from_internal_data(TAG_DHCP_RENEWAL_TIME, &period, sizeof(uint32_t)); + list_add(options, option); + + period = lease_get_expiry(lease); + option = dhcp_opt_create_from_internal_data(TAG_DHCP_IP_ADDRESS_LEASE_TIME, &period, sizeof(uint32_t)); + list_add(options, option); + + /* tack on the subnet option. */ + subnet = lease_get_subnet_mask(lease); + option = dhcp_opt_create_from_internal_data(TAG_DHCP_SUBNET_MASK, &subnet, IP_ADDR_LEN); + list_add(options, option); + + return options; + } + + /************************************** + * DHCP server message constructors. * + **************************************/ + + /* construct and send an offer. */ + static int server_do_offer(dhcp_server_control_t *sc, lease_t *lease, uint16_t *max_message_size_ptr, + eth_addr_t eth_addr, uint32_t xid) + { + uint16_t max_message_size = get_max_message_size(sc, max_message_size_ptr); + list_t *options; + dhcp_opt_t *option; + ip_addr_t yiaddr, to_addr; + dhcp_obj *dhcp = sc->rawnet->dhcp_p; + + /* get the options. */ + options = create_options_from_lease(sc, lease); + + /* get assigned address. */ + yiaddr = lease_get_address(lease); + + option = dhcp_opt_create_message_type(DHCP_OFFER_TM); + list_add(options, option); + + /* now build offer. */ + + /* if it was a relay server, we should unicast back to it so + * build a unicast packet and unicast. */ + + /* remove me. and do something with me. */ + max_message_size = 0; + + if(dhcp_get_giaddr(dhcp) != 0) { + + to_addr = ip_get_src_addr(sc->rawnet->ip_p); + + /* eth_addr is ignored because we'll be doing the unicast + * at the socket level and let the OS worry about it. */ + + build_dhcp_offer_unicast(sc->rawnet, dhcp_get_xid(dhcp), yiaddr, rawnet_get_ip_addr(sc->rawnet), + to_addr, eth_get_src_addr(sc->rawnet->ether_p), options); + + if(rawnet_send_packet_udp_socket_unicast(sc->udp_sock, sc->rawnet, to_addr)) { + FATAL_MESSAGE("could not send offer response"); + } + + } else { + + /* otherwise broadcast out. */ + + build_dhcp_offer_broadcast(sc->rawnet, dhcp_get_xid(dhcp), yiaddr, rawnet_get_ip_addr(sc->rawnet), + options); + + if(rawnet_send_packet_udp_socket_broadcast(sc->udp_sock, sc->rawnet)) { + FATAL_MESSAGE("could not send offer response"); + } + } + + return 0; + } + + /************************************** + * DHCP server message handlers. * + **************************************/ + + int server_handle_discover(dhcp_server_control_t *sc) + { + char *hostname = NULL; + eth_addr_t mac_addr; + uint8_t *chaddr; + ip_addr_t giaddr; + dhcp_opt_t *client_id = NULL; + dhcp_opt_t *opt; + lease_t *lease; + uint16_t *max_message_size = NULL; + dhcp_obj *dhcp = sc->rawnet->dhcp_p; + + /* a client wants to discover possible leases. get the + * information we need to pass to the lease manager and ask + * the manager if any leases are available for it. */ + + giaddr = dhcp_get_giaddr(dhcp); + + chaddr = dhcp_get_chaddr(dhcp); + memcpy(&mac_addr, chaddr, ETH_ADDR_LEN); + + dhcp_reset_option_seek(dhcp); + while((opt = dhcp_get_next_option(dhcp)) != NULL) { + + switch(dhcp_opt_get_tag(opt)) { + + case TAG_DHCP_CLIENT_ID: + client_id = opt; + break; + + case TAG_DHCP_MAX_DHCP_SIZE: + max_message_size = dhcp_opt_get_host_data(opt); + break; + + case TAG_DHCP_HOST_NAME: + hostname = dhcp_opt_get_host_data(opt); + break; + + default: + break; + } + } + + lease = lease_manager_lease_available(hostname, mac_addr, + giaddr, client_id); + + if(lease == NULL) + return STATE_LISTEN; /* we have no possible leases. */ + + /* otherwise we do have a lease, send out an OFFER. */ + + if(server_do_offer(sc, lease, max_message_size, mac_addr, dhcp_get_xid(dhcp))) + return STATE_SHUTDOWN; + + return STATE_LISTEN; + } + + int server_handle_request(dhcp_server_control_t *sc) + { + /* a client is requesting a lease, find out from the lease + * manager if we can give it the lease. */ + + return STATE_LISTEN; + } + + int server_handle_decline(dhcp_server_control_t *sc) + { + /* a client is declining a lease. let the lease manager know. */ + + return STATE_LISTEN; + } + + int server_handle_release(dhcp_server_control_t *sc) + { + /* a client is releasing a lease. let the lease manager know. */ + + return STATE_LISTEN; + } + /******************************* * event processing routines. * *************** *** 193,197 **** int server_handle_packet(dhcp_server_control_t *sc) { ! /* TODO. */ return STATE_LISTEN; } --- 385,434 ---- int server_handle_packet(dhcp_server_control_t *sc) { ! int retval; ! int message_type; ! ! retval = rawnet_get_packet_udp_socket(sc->udp_sock, sc->rawnet); ! ! switch(retval) { ! ! case RAWNET_MALFORMED_PACKET: ! return STATE_LISTEN; /* if packet malformed, just ignore it. */ ! ! case RAWNET_OK: ! ! /* check for a valid magic cookie, if not just drop it. */ ! if(!dhcp_valid_magic_cookie(sc->rawnet->dhcp_p)) ! break; ! ! /* based on the packet type, call the handler function. */ ! message_type = dhcp_get_type(sc->rawnet->dhcp_p); ! ! switch(message_type) { ! ! case DHCP_DISCOVER_TM: ! return server_handle_discover(sc); ! ! case DHCP_REQUEST_TM: ! return server_handle_request(sc); ! ! case DHCP_DECLINE_TM: ! return server_handle_decline(sc); ! ! case DHCP_RELEASE_TM: ! return server_handle_release(sc); ! ! default: ! /* anything else is silently ignored. */ ! break; ! } ! ! return STATE_LISTEN; ! ! default: /* anything else is an error. */ ! ERROR_MESSAGE("received error while reading UDP packet."); ! return STATE_SHUTDOWN; ! } ! ! /* we can ask rawnet to read from a socket. */ return STATE_LISTEN; } Index: dhcp-server.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-server.c 26 Jul 2003 23:48:01 -0000 1.10 --- dhcp-server.c 5 Aug 2003 05:01:02 -0000 1.11 *************** *** 32,35 **** --- 32,36 ---- #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-guile-util.h" #include "dhcp-server-guile.h" |
From: <act...@us...> - 2003-08-05 05:00:42
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26746/src Modified Files: dhcp-librawnet.h Log Message: added prototypes and globalized address constants Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dhcp-librawnet.h 25 Jul 2003 02:36:21 -0000 1.23 --- dhcp-librawnet.h 5 Aug 2003 05:00:38 -0000 1.24 *************** *** 180,183 **** --- 180,184 ---- uint16_t src_port, dst_port; /* udp ports for writing packets. */ + char *device; /* device name. */ *************** *** 223,226 **** --- 224,232 ---- /* constants. */ + extern const eth_addr_t eth_null; + extern const eth_addr_t eth_broadcast; + extern const ip_addr_t ip_addr_broadcast; + extern const ip_addr_t ip_addr_null; + /* Reasonable defaults in case services db isn't up to date. */ #define BOOTP_CLIENT 68 *************** *** 389,392 **** --- 395,401 ---- extern int rawnet_get_datalink_type(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); + extern int rawnet_send_packet_udp_socket_unicast(int sockd, rawnet_t *rawnet, ip_addr_t ip_addr); + extern int rawnet_send_packet_udp_socket_broadcast(int sockd, rawnet_t *rawnet); + extern int rawnet_get_packet_udp_socket(int sockd, rawnet_t *net); /* packet building routines. */ *************** *** 401,404 **** --- 410,416 ---- ip_addr_t sip_addr, eth_addr_t shw_addr); extern void build_dhcp_decline(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); + extern void build_dhcp_offer_unicast(rawnet_t *net, uint32_t xid, ip_addr_t yiaddr, ip_addr_t siaddr, + ip_addr_t to_addr, eth_addr_t to_eth_addr, list_t *options); + extern void build_dhcp_offer_broadcast(rawnet_t *net, uint32_t xid, ip_addr_t yiaddr, ip_addr_t siaddr, list_t *options); /* arp packet routines. */ *************** *** 442,445 **** --- 454,458 ---- extern uint8_t *dhcp_get_filename(dhcp_obj * dhcp); extern uint32_t dhcp_get_magic_cookie(dhcp_obj * dhcp); + extern int dhcp_get_type(dhcp_obj *dhcp); extern void dhcp_set_op(dhcp_obj * dhcp, uint8_t op); |
From: <act...@us...> - 2003-08-05 05:00:03
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26449/src Modified Files: dhcp-server-lease-manager.c dhcp-server-lease-manager.h Log Message: work on lease manager -- wrapper around server-guile bindings for lease management Index: dhcp-server-lease-manager.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-lease-manager.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-server-lease-manager.c 29 Jul 2003 02:38:14 -0000 1.1 --- dhcp-server-lease-manager.c 5 Aug 2003 05:00:00 -0000 1.2 *************** *** 40,67 **** } ! lease_definition_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return NULL; } ! lease_definition_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return NULL; } ! lease_definition_t *lease_manager_acquire_lease(lease_definition_t *lease) { ! return NULL; } ! int lease_manager_release_lease(lease_definition_t *lease) { ! return 0; } ! void lease_expire(lease_definition_t *lease) { ! return; } --- 40,69 ---- } ! lease_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return dhcp_guile_lease_available(hostname, mac_addr, ! giaddr, client_id); } ! lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return dhcp_guile_lookup_lease(ip_addr, hostname, mac_addr, ! giaddr, client_id); } ! int lease_manager_acquire_lease(lease_t *lease) { ! return dhcp_guile_acquire_lease(lease); } ! int lease_manager_release_lease(lease_t *lease) { ! return dhcp_guile_release_lease(lease); } ! void lease_manager_lease_expire(void) { ! return dhcp_guile_lease_expire(); } Index: dhcp-server-lease-manager.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-lease-manager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-server-lease-manager.h 29 Jul 2003 02:38:14 -0000 1.1 --- dhcp-server-lease-manager.h 5 Aug 2003 05:00:00 -0000 1.2 *************** *** 26,37 **** extern int initialize_lease_manager(void); ! extern lease_definition_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_definition_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_definition_t *lease_manager_acquire_lease(lease_definition_t *lease); ! extern int lease_manager_release_lease(lease_definition_t *lease); ! extern void lease_expire(lease_definition_t *lease); #endif /* DHCP_SERVER_LEASE_MANAGER_H */ - --- 26,36 ---- extern int initialize_lease_manager(void); ! extern lease_t *lease_manager_lease_available(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_t *lease_manager_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern int lease_manager_acquire_lease(lease_t *lease); ! extern int lease_manager_release_lease(lease_t *lease); ! extern void lease_manager_lease_expire(void); #endif /* DHCP_SERVER_LEASE_MANAGER_H */ |
From: <act...@us...> - 2003-08-05 04:59:35
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26394/src Modified Files: dhcp-server-guile.c dhcp-server-guile.h Log Message: more work on server guile bindings Index: dhcp-server-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-server-guile.c 29 Jul 2003 02:38:14 -0000 1.2 --- dhcp-server-guile.c 5 Aug 2003 04:59:32 -0000 1.3 *************** *** 34,41 **** #include "dhcp-server-conf.h" #include "dhcp-server.h" #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag; ! static SCM initialize_leases, get_next_lease, lease_lookup, lease_expire; /* * * * * * * * * * * * * * * * * * * * --- 34,192 ---- #include "dhcp-server-conf.h" #include "dhcp-server.h" + #include "dhcp-guile-util.h" #include "dhcp-server-guile.h" ! static scm_t_bits server_control_tag, lease_tag; ! SCM leases_initialize, lease_available, lease_lookup, lease_acquire, lease_release, lease_expire; ! ! /* * * * * * * * * * * * * * * * * * * * ! * misc utilities * ! * * * * * * * * * * * * * * * * * * * */ ! ! static SCM make_lease_data_list(const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id) ! { ! SCM data_list; ! char *eth_addr_string, *giaddr_string, *client_id_string; ! ! eth_addr_string = eth_addr_to_string(mac_addr); ! giaddr_string = ip_addr_to_string(giaddr); ! client_id_string = dhcp_opt_get_user_string(client_id); ! ! data_list = SCM_EOL; ! data_list = scm_cons(scm_makfrom0str(client_id_string), data_list); ! data_list = scm_cons(scm_makfrom0str(giaddr_string), data_list); ! data_list = scm_cons(scm_makfrom0str(eth_addr_string), data_list); ! data_list = scm_cons(scm_makfrom0str(hostname), data_list); ! ! xfree(eth_addr_string); ! xfree(giaddr_string); ! xfree(client_id_string); ! ! return data_list; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * lease smob * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* mark a lease: we don't need to do any marking. */ ! static SCM scm_lease_mark(SCM scm_lease) ! { ! return SCM_BOOL_F; ! } ! ! /* free a lease scm. */ ! static size_t scm_lease_free(SCM scm_lease) ! { ! lease_smob_t *lease; ! ! lease = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! lease_destroy(lease->lease); ! xfree(lease); ! ! return sizeof(lease_smob_t); ! } ! ! /* print out a lease scm. */ ! static int scm_lease_print(SCM scm_lease, SCM port, scm_print_state *pstate) ! { ! scm_puts("#<lease>", port); ! return 1; ! } ! ! /* create a lease: this is called from within the scheme environment. */ ! static SCM scm_make_lease(SCM scm_ip_address, SCM scm_subnet_mask, SCM scm_lease_expiry, ! SCM scm_renew_time, SCM scm_rebind_time) ! { ! lease_smob_t *lease_smob; ! lease_t *lease; ! ip_addr_t ip_address, subnet_mask; ! uint32_t lease_expiry, renew_time, rebind_time; ! ! /* do assertions: all arguments can either be strings or inums */ ! ! SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), ! scm_ip_address, SCM_ARG1, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_subnet_mask)|SCM_INUMP(scm_subnet_mask), ! scm_subnet_mask, SCM_ARG2, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_lease_expiry)|SCM_INUMP(scm_lease_expiry), ! scm_lease_expiry, SCM_ARG3, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_renew_time)|SCM_INUMP(scm_renew_time), ! scm_renew_time, SCM_ARG4, "make-lease"); ! ! SCM_ASSERT(SCM_STRINGP(scm_rebind_time)|SCM_INUMP(scm_rebind_time), ! scm_rebind_time, SCM_ARG5, "make-lease"); ! ! /* if string change to number first. */ ! ! if(SCM_STRINGP(scm_ip_address)) { ! ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "make-lease")); ! } else { ! ip_address = scm_num2ulong(scm_ip_address, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_subnet_mask)) { ! subnet_mask = ntohl(scm_num2ulong(scm_inet_aton(scm_subnet_mask), 1, "make-lease")); ! } else { ! subnet_mask = scm_num2ulong(scm_subnet_mask, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_lease_expiry)) { ! lease_expiry = scm_num2ulong(scm_inet_aton(scm_lease_expiry), 1, "make-lease"); ! } else { ! lease_expiry = scm_num2ulong(scm_lease_expiry, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_renew_time)) { ! renew_time = scm_num2ulong(scm_inet_aton(scm_renew_time), 1, "make-lease"); ! } else { ! renew_time = scm_num2ulong(scm_renew_time, 1, "make-lease"); ! } ! ! if(SCM_STRINGP(scm_rebind_time)) { ! rebind_time = scm_num2ulong(scm_inet_aton(scm_rebind_time), 1, "make-lease"); ! } else { ! rebind_time = scm_num2ulong(scm_rebind_time, 1, "make-lease"); ! } ! ! lease = lease_create(ip_address, subnet_mask, lease_expiry, renew_time, rebind_time); ! lease_smob = scm_must_malloc(sizeof(lease_smob_t), "lease-make"); ! lease_smob->lease = lease; ! ! SCM_RETURN_NEWSMOB(lease_tag, lease); ! } ! ! /* create an SCM lease: this is called from the C code: a copy is ! made so garbage collection doesn't clubber our copy */ ! static SCM scm_c_make_lease(lease_t *lease) ! { ! return scm_make_lease(SCM_MAKINUM(lease_get_address(lease)), SCM_MAKINUM(lease_get_subnet_mask(lease)), ! SCM_MAKINUM(lease_get_expiry(lease)), SCM_MAKINUM(lease_get_renew(lease)), ! SCM_MAKINUM(lease_get_rebind(lease))); ! } ! ! /* get a copy of the lease from the scm lease: caled from C code. */ ! static lease_t * scm_c_get_lease(SCM scm_lease) ! { ! lease_smob_t *lease_smob; ! ! lease_smob = (lease_smob_t *)SCM_SMOB_DATA(scm_lease); ! return lease_copy(lease_smob->lease); ! } ! ! /* initialization routines for server control SMOB. */ ! static void init_lease_smob(void) ! { ! lease_tag = scm_make_smob_type("lease", sizeof(lease_smob_t)); ! ! scm_set_smob_free(lease_tag, scm_lease_free); ! scm_set_smob_mark(lease_tag, scm_lease_mark); ! scm_set_smob_print(lease_tag, scm_lease_print); ! ! return; ! } /* * * * * * * * * * * * * * * * * * * * *************** *** 72,80 **** server_control_smob_t *server_control_smob; ! server_control_smob = xmalloc(sizeof(server_control_smob_t)); server_control_smob->sc = sc; SCM_RETURN_NEWSMOB(server_control_tag, server_control_smob); - } --- 223,230 ---- server_control_smob_t *server_control_smob; ! server_control_smob = scm_must_malloc(sizeof(server_control_smob_t), "scm_make_server_control"); server_control_smob->sc = sc; SCM_RETURN_NEWSMOB(server_control_tag, server_control_smob); } *************** *** 85,90 **** /* bind mark, free, and print. */ - scm_set_smob_mark(server_control_tag, dhcp_scm_server_control_mark); scm_set_smob_free(server_control_tag, dhcp_scm_server_control_free); scm_set_smob_print(server_control_tag, dhcp_scm_server_control_print); --- 235,240 ---- /* bind mark, free, and print. */ scm_set_smob_free(server_control_tag, dhcp_scm_server_control_free); + scm_set_smob_mark(server_control_tag, dhcp_scm_server_control_mark); scm_set_smob_print(server_control_tag, dhcp_scm_server_control_print); *************** *** 135,147 **** void dhcp_guile_init(dhcp_server_control_t *sc) { - /* initialize the server control smob. */ init_server_control_smob(); /* bind symbols to top level so that the user defined script can hook into them. */ ! initialize_leases = scm_str2symbol("initialize-leases"); ! get_next_lease = scm_str2symbol("get-next-lease"); lease_lookup = scm_str2symbol("lease-lookup"); lease_expire = scm_str2symbol("lease-expire"); --- 285,301 ---- void dhcp_guile_init(dhcp_server_control_t *sc) { /* initialize the server control smob. */ init_server_control_smob(); + /* initialize lease smob. */ + init_lease_smob(); + /* bind symbols to top level so that the user defined script can hook into them. */ ! leases_initialize = scm_str2symbol("initialize-leases"); ! lease_available = scm_str2symbol("lease-available?"); lease_lookup = scm_str2symbol("lease-lookup"); + lease_acquire = scm_str2symbol("lease-acquire"); + lease_release = scm_str2symbol("lease-release"); lease_expire = scm_str2symbol("lease-expire"); *************** *** 149,161 **** * collector from swallowing these symbols up. */ ! scm_define(initialize_leases, SCM_BOOL_F); ! scm_define(get_next_lease, SCM_BOOL_F); scm_define(lease_lookup, SCM_BOOL_F); scm_define(lease_expire, SCM_BOOL_F); - /* define all the subroutines. */ - - /* TODO. */ - /* bind our server control object. */ scm_c_define("dhcp-server-control", --- 303,315 ---- * collector from swallowing these symbols up. */ ! /* bind false to all the subroutines. */ ! ! scm_define(leases_initialize, SCM_BOOL_F); ! scm_define(lease_available, SCM_BOOL_F); scm_define(lease_lookup, SCM_BOOL_F); + scm_define(lease_acquire, SCM_BOOL_F); + scm_define(lease_release, SCM_BOOL_F); scm_define(lease_expire, SCM_BOOL_F); /* bind our server control object. */ scm_c_define("dhcp-server-control", *************** *** 171,202 **** int dhcp_guile_initialize_leases(void) { ! scm_apply_0(initialize_leases, SCM_EOL); return 0; } /* ask if any leases are available. */ ! lease_definition_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return NULL; } /* lookup a lease: lookup a lease. */ ! lease_definition_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id) { ! return NULL; } /* get the next available lease. */ ! lease_definition_t *dhcp_guile_acquire_lease(lease_definition_t *definition) { ! return NULL; } /* lookup an existing lease. */ ! lease_definition_t *dhcp_guile_release_lease(lease_definition_t *definition) { ! return NULL; } --- 325,390 ---- int dhcp_guile_initialize_leases(void) { ! scm_call_0(scm_variable_ref(leases_initialize)); return 0; } /* ask if any leases are available. */ ! lease_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id) { ! SCM data_list, scm_lease; ! lease_t *lease; ! ! data_list = make_lease_data_list(hostname, mac_addr, giaddr, client_id); ! scm_lease = scm_call_1(scm_variable_ref(lease_available), data_list); ! ! lease = scm_c_get_lease(scm_lease); ! return lease; } /* lookup a lease: lookup a lease. */ ! lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ip_addr_t giaddr, dhcp_opt_t *client_id) { ! SCM data_list, scm_lease; ! lease_t *lease; ! ! data_list = make_lease_data_list(hostname, mac_addr, giaddr, client_id); ! scm_lease = scm_call_1(scm_variable_ref(lease_lookup), data_list); ! ! lease = scm_c_get_lease(scm_lease); ! return lease; } /* get the next available lease. */ ! int dhcp_guile_acquire_lease(lease_t *lease) { ! SCM scm_lease; ! SCM scm_return; ! ! scm_lease = scm_c_make_lease(lease); ! ! scm_return = scm_call_1(scm_variable_ref(lease_acquire), scm_lease); ! ! if(scm_return == SCM_BOOL_T) ! return 0; ! else ! return 1; } /* lookup an existing lease. */ ! int dhcp_guile_release_lease(lease_t *lease) { ! SCM scm_lease; ! SCM scm_return; ! ! scm_lease = scm_c_make_lease(lease); ! ! scm_return = scm_call_1(scm_variable_ref(lease_release), scm_lease); ! ! if(scm_return == SCM_BOOL_T) ! return 0; ! else ! return 1; } *************** *** 204,207 **** --- 392,396 ---- void dhcp_guile_lease_expire(void) { + scm_call_0(scm_variable_ref(lease_expire)); return; } Index: dhcp-server-guile.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-guile.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-server-guile.h 29 Jul 2003 02:38:14 -0000 1.3 --- dhcp-server-guile.h 5 Aug 2003 04:59:32 -0000 1.4 *************** *** 26,45 **** #define DHCP_SERVER_GUILE_H - #include <libguile.h> - typedef struct client_control_smob { dhcp_server_control_t *sc; } server_control_smob_t; /* prototypes. */ extern void dhcp_guile_init(dhcp_server_control_t *sc); extern int dhcp_guile_initialize_leases(void); ! extern lease_definition_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_definition_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_definition_t *dhcp_guile_acquire_lease(lease_definition_t *definition); ! extern lease_definition_t *dhcp_guile_release_lease(lease_definition_t *definition); extern void dhcp_guile_lease_expire(void); --- 26,47 ---- #define DHCP_SERVER_GUILE_H typedef struct client_control_smob { dhcp_server_control_t *sc; } server_control_smob_t; + typedef struct lease_smob { + lease_t *lease; + } lease_smob_t; + /* prototypes. */ extern void dhcp_guile_init(dhcp_server_control_t *sc); extern int dhcp_guile_initialize_leases(void); ! extern lease_t *dhcp_guile_lease_available(const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern lease_t *dhcp_guile_lookup_lease(ip_addr_t ip_addr, const char *hostname, eth_addr_t mac_addr, ! ip_addr_t giaddr, dhcp_opt_t *client_id); ! extern int dhcp_guile_acquire_lease(lease_t *definition); ! extern int dhcp_guile_release_lease(lease_t *definition); extern void dhcp_guile_lease_expire(void); |
From: <act...@us...> - 2003-08-05 04:59:14
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26361/src Modified Files: dhcp-lease.c dhcp-lease.h Log Message: new routines for lease data Index: dhcp-lease.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-lease.c 26 Jul 2003 23:47:08 -0000 1.7 --- dhcp-lease.c 5 Aug 2003 04:59:12 -0000 1.8 *************** *** 165,168 **** --- 165,194 ---- }; + lease_t *lease_create(ip_addr_t ip_address, ip_addr_t subnet_mask, uint32_t lease_expiry, + uint32_t renew_time, uint32_t rebind_time) + { + lease_t *lease; + + lease = xcalloc(sizeof(lease_t)); + lease->address = ip_address; + lease->subnet_mask = subnet_mask; + lease->lease_expiry = lease_expiry; + lease->renew_time = renew_time; + lease->rebind_time = rebind_time; + + return lease; + } + + void lease_destroy(lease_t *lease) + { + xfree(lease); + } + + lease_t *lease_copy(lease_t *lease) + { + return lease_create(lease->address, lease->subnet_mask, lease->lease_expiry, + lease->renew_time, lease->rebind_time); + } + /* * * * * * * * * accessors. * *************** *** 241,244 **** --- 267,365 ---- { return lease->subnet_mask; + } + + uint32_t lease_definition_get_renew(lease_definition_t *lease) + { + return lease->renew_time; + } + + uint32_t lease_definition_get_rebind(lease_definition_t *lease) + { + return lease->rebind_time; + } + + uint32_t lease_definition_get_expiry(lease_definition_t *lease) + { + return lease->lease_expiry; + } + + list_t *lease_definition_get_options(lease_definition_t *lease) + { + return lease->options; + } + + /* lease. */ + + list_t *lease_get_options(lease_t *lease_data) + { + return lease_data->options; + } + + uint32_t lease_get_renew(lease_t *lease_data) + { + return lease_data->renew_time; + } + + uint32_t lease_get_rebind(lease_t *lease_data) + { + return lease_data->rebind_time; + } + + uint32_t lease_get_expiry(lease_t *lease_data) + { + return lease_data->lease_expiry; + } + + ip_addr_t lease_get_subnet_mask(lease_t *lease_data) + { + return lease_data->subnet_mask; + } + + ip_addr_t lease_get_address(lease_t *lease_data) + { + return lease_data->address; + } + + /* modifiers. */ + + /* lease_t */ + + void lease_set_options(lease_t *lease_data, list_t *options) + { + if(lease_data->options != NULL) + dhcp_opt_destroy_option_list(lease_data->options); + + lease_data->options = options; + return; + } + + void lease_set_renew(lease_t *lease_data, uint32_t renew_time) + { + lease_data->renew_time = renew_time; + return; + } + + void lease_set_rebind(lease_t *lease_data, uint32_t rebind_time) + { + lease_data->rebind_time = rebind_time; + return; + } + + void lease_set_expiry(lease_t *lease_data, uint32_t lease_expiry) + { + lease_data->lease_expiry = lease_expiry; + return; + } + + void lease_set_subnet_mask(lease_t *lease_data, ip_addr_t subnet_mask) + { + lease_data->subnet_mask = subnet_mask; + return; + } + + void lease_set_address(lease_t *lease_data, ip_addr_t ip_address) + { + lease_data->address = ip_address; + return; } Index: dhcp-lease.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-lease.h 26 Jul 2003 23:47:08 -0000 1.6 --- dhcp-lease.h 5 Aug 2003 04:59:12 -0000 1.7 *************** *** 70,79 **** typedef struct { - lease_definition_t *definition; /* lease definition. */ - ip_addr_t address; /* assigned address. */ time_t ini_assigned; /* initially assigned timestamp. */ time_t last_assigned; /* last assigned timestamp. */ } lease_t; --- 70,84 ---- typedef struct { ip_addr_t address; /* assigned address. */ + ip_addr_t subnet_mask; /* subnet mask. */ + + uint32_t lease_expiry; /* lease expiry time. */ + uint32_t renew_time; /* renewal time. */ + uint32_t rebind_time; /* rebind time. */ + time_t ini_assigned; /* initially assigned timestamp. */ time_t last_assigned; /* last assigned timestamp. */ + list_t *options; /* options. */ } lease_t; *************** *** 115,118 **** --- 120,145 ---- extern ip_addr_t lease_definition_get_subnet_addr(lease_definition_t *lease); extern ip_addr_t lease_definition_get_subnet_mask(lease_definition_t *lease); + extern list_t *lease_definition_get_options(lease_definition_t *lease); + extern uint32_t lease_definition_get_renew(lease_definition_t *lease); + extern uint32_t lease_definition_get_rebind(lease_definition_t *lease); + extern uint32_t lease_definition_get_expiry(lease_definition_t *lease); + + extern list_t *lease_get_options(lease_t *lease_data); + extern uint32_t lease_get_renew(lease_t *lease_data); + extern uint32_t lease_get_rebind(lease_t *lease_data); + extern uint32_t lease_get_expiry(lease_t *lease_data); + extern ip_addr_t lease_get_subnet_mask(lease_t *lease_data); + extern ip_addr_t lease_get_address(lease_t *lease_data); + extern void lease_set_options(lease_t *lease_data, list_t *options); + extern void lease_set_renew(lease_t *lease_data, uint32_t renew_time); + extern void lease_set_rebind(lease_t *lease_data, uint32_t rebind_time); + extern void lease_set_expiry(lease_t *lease_data, uint32_t lease_expiry); + extern void lease_set_subnet_mask(lease_t *lease_data, ip_addr_t subnet_mask); + extern void lease_set_address(lease_t *lease_data, ip_addr_t ip_address); + + extern lease_t *lease_create(ip_addr_t ip_address, ip_addr_t subnet_mask, uint32_t lease_expiry, + uint32_t renew_time, uint32_t rebind_time); + extern void lease_destroy(lease_t *lease); + extern lease_t *lease_copy(lease_t *lease); extern void pretty_print_lease_def(lease_definition_t *lease_def); |