ReactOS 0.4.17-dev-243-g1369312
dhclient.c File Reference
#include <rosdhcp.h>
Include dependency graph for dhclient.c:

Go to the source code of this file.

Macros

#define PERIOD   0x2e
 
#define hyphenchar(c)   ((c) == 0x2d)
 
#define bslashchar(c)   ((c) == 0x5c)
 
#define periodchar(c)   ((c) == PERIOD)
 
#define asterchar(c)   ((c) == 0x2a)
 
#define alphachar(c)
 
#define digitchar(c)   ((c) >= 0x30 && (c) <= 0x39)
 
#define borderchar(c)   (alphachar(c) || digitchar(c))
 
#define middlechar(c)   (borderchar(c) || hyphenchar(c))
 
#define domainchar(c)   ((c) > 0x20 && (c) < 0x7f)
 
#define ASSERT_STATE(state_is, state_shouldbe)   {}
 
#define TIME_MAX   2147483647
 
#define ADVANCE(x, n)   (x += ROUNDUP((n)->sa_len))
 

Functions

void usage (void)
 
int check_option (struct client_lease *l, int option)
 
int ipv4addrs (char *buf)
 
int res_hnok (const char *dn)
 
charoption_as_string (unsigned int code, unsigned char *data, int len)
 
int fork_privchld (int, int)
 
int check_arp (struct interface_info *ip, struct client_lease *lp)
 
int init_client (void)
 
void stop_client (void)
 
void state_reboot (void *ipp)
 
void state_init (void *ipp)
 
void state_release (void *ipp)
 
void state_selecting (void *ipp)
 
void dhcpack (struct packet *packet)
 
void set_name_servers (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void unset_name_servers (PDHCP_ADAPTER Adapter)
 
void set_domain (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void unset_domain (PDHCP_ADAPTER Adapter)
 
void setup_adapter (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void reset_adapter (PDHCP_ADAPTER Adapter)
 
void bind_lease (struct interface_info *ip)
 
void unbind_lease (struct interface_info *ip)
 
void state_bound (void *ipp)
 
void bootp (struct packet *packet)
 
void dhcp (struct packet *packet)
 
void dhcpoffer (struct packet *packet)
 
struct client_leasepacket_to_lease (struct packet *packet)
 
void dhcpnak (struct packet *packet)
 
void send_discover (void *ipp)
 
void state_panic (void *ipp)
 
void send_request (void *ipp)
 
void send_decline (void *ipp)
 
void send_release (void *ipp)
 
void make_discover (struct interface_info *ip, struct client_lease *lease)
 
void make_request (struct interface_info *ip, struct client_lease *lease)
 
void make_decline (struct interface_info *ip, struct client_lease *lease)
 
void make_release (struct interface_info *ip, struct client_lease *lease)
 
void free_client_lease (struct client_lease *lease)
 
void rewrite_client_leases (struct interface_info *ifi)
 
void write_client_lease (struct interface_info *ip, struct client_lease *lease, int rewrite)
 
void priv_script_init (struct interface_info *ip, char *reason, char *medium)
 
void priv_script_write_params (struct interface_info *ip, char *prefix, struct client_lease *lease)
 
int dhcp_option_ev_name (char *buf, size_t buflen, struct dhcp_option *option)
 

Variables

unsigned long debug_trace_level = 0
 
charpath_dhclient_conf = _PATH_DHCLIENT_CONF
 
charpath_dhclient_db = NULL
 
int log_perror = 1
 
int privfd
 
struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }
 
struct in_addr inaddr_any
 
struct sockaddr_in sockaddr_broadcast
 
int log_priority
 
int no_daemon
 
int unknown_ok = 1
 
int routefd
 
time_t scripttime
 
FILEleaseFile
 

Macro Definition Documentation

◆ ADVANCE

#define ADVANCE (   x,
  n 
)    (x += ROUNDUP((n)->sa_len))

Definition at line 105 of file dhclient.c.

◆ alphachar

#define alphachar (   c)
Value:
(((c) >= 0x41 && (c) <= 0x5a) || \
((c) >= 0x61 && (c) <= 0x7a))
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Definition at line 63 of file dhclient.c.

◆ ASSERT_STATE

#define ASSERT_STATE (   state_is,
  state_shouldbe 
)    {}

Definition at line 88 of file dhclient.c.

◆ asterchar

#define asterchar (   c)    ((c) == 0x2a)

Definition at line 62 of file dhclient.c.

◆ borderchar

#define borderchar (   c)    (alphachar(c) || digitchar(c))

Definition at line 67 of file dhclient.c.

◆ bslashchar

#define bslashchar (   c)    ((c) == 0x5c)

Definition at line 60 of file dhclient.c.

◆ digitchar

#define digitchar (   c)    ((c) >= 0x30 && (c) <= 0x39)

Definition at line 65 of file dhclient.c.

◆ domainchar

#define domainchar (   c)    ((c) > 0x20 && (c) < 0x7f)

Definition at line 69 of file dhclient.c.

◆ hyphenchar

#define hyphenchar (   c)    ((c) == 0x2d)

Definition at line 59 of file dhclient.c.

◆ middlechar

#define middlechar (   c)    (borderchar(c) || hyphenchar(c))

Definition at line 68 of file dhclient.c.

◆ PERIOD

#define PERIOD   0x2e

Definition at line 58 of file dhclient.c.

◆ periodchar

#define periodchar (   c)    ((c) == PERIOD)

Definition at line 61 of file dhclient.c.

◆ TIME_MAX

#define TIME_MAX   2147483647

Definition at line 90 of file dhclient.c.

Function Documentation

◆ bind_lease()

void bind_lease ( struct interface_info ip)

Definition at line 707 of file dhclient.c.

708{
709 PDHCP_ADAPTER Adapter;
710 struct client_lease *new_lease = ip->client->new;
712
713 time(&cur_time);
714
715 /* Remember the medium. */
716 ip->client->new->medium = ip->client->medium;
717
718 /* Replace the old active lease with the new one. */
719 if (ip->client->active)
720 free_client_lease(ip->client->active);
721 ip->client->active = ip->client->new;
722 ip->client->new = NULL;
723
724 /* Set up a timeout to start the renewal process. */
725 /* Timeout of zero means no timeout (some implementations seem to use
726 * one day).
727 */
728 if( ip->client->active->renewal - cur_time )
729 add_timeout(ip->client->active->renewal, state_bound, ip);
730
731 note("bound to %s -- renewal in %ld seconds.",
732 piaddr(ip->client->active->address),
733 (long int)(ip->client->active->renewal - cur_time));
734
735 ip->client->state = S_BOUND;
736
737 Adapter = AdapterFindInfo( ip );
738
739 if( Adapter ) setup_adapter( Adapter, new_lease );
740 else {
741 warning("Could not find adapter for info %p\n", ip);
742 return;
743 }
744 set_name_servers( Adapter, new_lease );
745 set_domain( Adapter, new_lease );
746}
PDHCP_ADAPTER AdapterFindInfo(struct interface_info *ip)
Definition: adapter.c:638
void add_timeout(time_t when, void(*where)(void *), void *what)
Definition: dispatch.c:253
int note(char *format,...)
Definition: util.c:12
char * piaddr(struct iaddr addr)
Definition: util.c:6
void free_client_lease(struct client_lease *lease)
Definition: dhclient.c:1900
void state_bound(void *ipp)
Definition: dhclient.c:777
void setup_adapter(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:561
void set_domain(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:483
void set_name_servers(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:421
time_t cur_time
@ S_BOUND
Definition: dhcpd.h:176
#define NULL
Definition: types.h:112
__time32_t time_t
Definition: corecrt.h:228
__u16 time
Definition: mkdosfs.c:8
#define warning(s)
Definition: debug.h:83
Definition: dhcpd.h:62

Referenced by dhcpack(), and state_selecting().

◆ bootp()

void bootp ( struct packet packet)

Definition at line 803 of file dhclient.c.

804{
805 struct iaddrlist *ap;
806
807 if (packet->raw->op != BOOTREPLY)
808 return;
809
810 /* If there's a reject list, make sure this packet's sender isn't
811 on it. */
812 for (ap = packet->interface->client->config->reject_list;
813 ap; ap = ap->next) {
814 if (addr_eq(packet->client_addr, ap->addr)) {
815 note("BOOTREPLY from %s rejected.", piaddr(ap->addr));
816 return;
817 }
818 }
820}
int addr_eq(struct iaddr a, struct iaddr b)
Definition: util.c:100
#define BOOTREPLY
Definition: dhcp.h:79
void dhcpoffer(struct packet *packet)
Definition: dhclient.c:859
Definition: dhcpd.h:135
struct dhcp_packet * raw
Definition: dhcpd.h:136
struct interface_info * interface
Definition: dhcpd.h:142
struct iaddr client_addr
Definition: dhcpd.h:141
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by do_packet().

◆ check_arp()

int check_arp ( struct interface_info ip,
struct client_lease lp 
)

Definition at line 137 of file dhclient.c.

137 {
138 return 1;
139}

Referenced by dhcpoffer(), and state_selecting().

◆ check_option()

int check_option ( struct client_lease l,
int  option 
)

Definition at line 2198 of file dhclient.c.

2199{
2200 char *opbuf;
2201 char *sbuf;
2202
2203 /* we use this, since this is what gets passed to dhclient-script */
2204
2205 opbuf = pretty_print_option(option, l->options[option].data,
2206 l->options[option].len, 0, 0);
2207
2208 sbuf = option_as_string(option, l->options[option].data,
2209 l->options[option].len);
2210
2211 switch (option) {
2212 case DHO_SUBNET_MASK:
2213 case DHO_TIME_SERVERS:
2214 case DHO_NAME_SERVERS:
2215 case DHO_ROUTERS:
2217 case DHO_LOG_SERVERS:
2218 case DHO_COOKIE_SERVERS:
2219 case DHO_LPR_SERVERS:
2222 case DHO_SWAP_SERVER:
2224 case DHO_NIS_SERVERS:
2225 case DHO_NTP_SERVERS:
2228 case DHO_FONT_SERVERS:
2230 if (!ipv4addrs(opbuf)) {
2231 warning("Invalid IP address in option(%d): %s", option, opbuf);
2232 return (0);
2233 }
2234 return (1) ;
2235 case DHO_HOST_NAME:
2236 case DHO_DOMAIN_NAME:
2237 case DHO_NIS_DOMAIN:
2238 if (!res_hnok(sbuf))
2239 warning("Bogus Host Name option %d: %s (%s)", option,
2240 sbuf, opbuf);
2241 return (1);
2242 case DHO_PAD:
2243 case DHO_TIME_OFFSET:
2244 case DHO_BOOT_SIZE:
2245 case DHO_MERIT_DUMP:
2246 case DHO_ROOT_PATH:
2248 case DHO_IP_FORWARDING:
2250 case DHO_POLICY_FILTER:
2252 case DHO_DEFAULT_IP_TTL:
2255 case DHO_INTERFACE_MTU:
2258 case DHO_MASK_SUPPLIER:
2261 case DHO_STATIC_ROUTES:
2270 case DHO_NETBIOS_SCOPE:
2277 case DHO_DHCP_MESSAGE:
2284 case DHO_END:
2285 return (1);
2286 default:
2287 warning("unknown dhcp option value 0x%x", option);
2288 return (unknown_ok);
2289 }
2290}
char * pretty_print_option(unsigned int code, unsigned char *data, int len, int emit_commas, int emit_quotes)
Definition: options.c:396
#define DHO_DHCP_MESSAGE
Definition: dhcp.h:152
#define DHO_MASK_SUPPLIER
Definition: dhcp.h:126
#define DHO_TCP_KEEPALIVE_GARBAGE
Definition: dhcp.h:135
#define DHO_DHCP_MAX_MESSAGE_SIZE
Definition: dhcp.h:153
#define DHO_ROUTER_DISCOVERY
Definition: dhcp.h:127
#define DHO_NAME_SERVERS
Definition: dhcp.h:101
#define DHO_VENDOR_ENCAPSULATED_OPTIONS
Definition: dhcp.h:139
#define DHO_PERFORM_MASK_DISCOVERY
Definition: dhcp.h:125
#define DHO_NIS_SERVERS
Definition: dhcp.h:137
#define DHO_NON_LOCAL_SOURCE_ROUTING
Definition: dhcp.h:116
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_MERIT_DUMP
Definition: dhcp.h:110
#define DHO_NETBIOS_NAME_SERVERS
Definition: dhcp.h:140
#define DHO_DHCP_PARAMETER_REQUEST_LIST
Definition: dhcp.h:151
#define DHO_FONT_SERVERS
Definition: dhcp.h:144
#define DHO_NETBIOS_SCOPE
Definition: dhcp.h:143
#define DHO_LOG_SERVERS
Definition: dhcp.h:103
#define DHO_NETBIOS_NODE_TYPE
Definition: dhcp.h:142
#define DHO_NIS_DOMAIN
Definition: dhcp.h:136
#define DHO_PAD
Definition: dhcp.h:96
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define DHO_TCP_KEEPALIVE_INTERVAL
Definition: dhcp.h:134
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
#define DHO_TIME_SERVERS
Definition: dhcp.h:100
#define DHO_NETBIOS_DD_SERVER
Definition: dhcp.h:141
#define DHO_IP_FORWARDING
Definition: dhcp.h:115
#define DHO_IMPRESS_SERVERS
Definition: dhcp.h:106
#define DHO_TRAILER_ENCAPSULATION
Definition: dhcp.h:130
#define DHO_PATH_MTU_PLATEAU_TABLE
Definition: dhcp.h:121
#define DHO_DHCP_USER_CLASS_ID
Definition: dhcp.h:158
#define DHO_EXTENSIONS_PATH
Definition: dhcp.h:114
#define DHO_DHCP_CLIENT_IDENTIFIER
Definition: dhcp.h:157
#define DHO_TIME_OFFSET
Definition: dhcp.h:98
#define DHO_DEFAULT_TCP_TTL
Definition: dhcp.h:133
#define DHO_DHCP_MESSAGE_TYPE
Definition: dhcp.h:149
#define DHO_INTERFACE_MTU
Definition: dhcp.h:122
#define DHO_X_DISPLAY_MANAGER
Definition: dhcp.h:145
#define DHO_POLICY_FILTER
Definition: dhcp.h:117
#define DHO_ALL_SUBNETS_LOCAL
Definition: dhcp.h:123
#define DHO_MAX_DGRAM_REASSEMBLY
Definition: dhcp.h:118
#define DHO_END
Definition: dhcp.h:159
#define DHO_COOKIE_SERVERS
Definition: dhcp.h:104
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
#define DHO_DHCP_RENEWAL_TIME
Definition: dhcp.h:154
#define DHO_SWAP_SERVER
Definition: dhcp.h:112
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
#define DHO_DEFAULT_IP_TTL
Definition: dhcp.h:119
#define DHO_BOOT_SIZE
Definition: dhcp.h:109
#define DHO_DHCP_REBINDING_TIME
Definition: dhcp.h:155
#define DHO_DHCP_OPTION_OVERLOAD
Definition: dhcp.h:148
#define DHO_DHCP_SERVER_IDENTIFIER
Definition: dhcp.h:150
#define DHO_ROOT_PATH
Definition: dhcp.h:113
#define DHO_ARP_CACHE_TIMEOUT
Definition: dhcp.h:131
#define DHO_ROUTERS
Definition: dhcp.h:99
#define DHO_IEEE802_3_ENCAPSULATION
Definition: dhcp.h:132
#define DHO_DHCP_REQUESTED_ADDRESS
Definition: dhcp.h:146
#define DHO_DHCP_LEASE_TIME
Definition: dhcp.h:147
#define DHO_STATIC_ROUTES
Definition: dhcp.h:129
#define DHO_SUBNET_MASK
Definition: dhcp.h:97
#define DHO_DHCP_CLASS_IDENTIFIER
Definition: dhcp.h:156
#define DHO_LPR_SERVERS
Definition: dhcp.h:105
#define DHO_ROUTER_SOLICITATION_ADDRESS
Definition: dhcp.h:128
#define DHO_PATH_MTU_AGING_TIMEOUT
Definition: dhcp.h:120
#define DHO_RESOURCE_LOCATION_SERVERS
Definition: dhcp.h:107
r l[0]
Definition: byte_order.h:168
int unknown_ok
Definition: dhclient.c:94
int ipv4addrs(char *buf)
Definition: dhclient.c:2322
char * option_as_string(unsigned int code, unsigned char *data, int len)
Definition: dhclient.c:2342
int res_hnok(const char *dn)
Definition: dhclient.c:2293
Definition: getopt.h:109

Referenced by packet_to_lease().

◆ dhcp()

void dhcp ( struct packet packet)

Definition at line 823 of file dhclient.c.

824{
825 struct iaddrlist *ap;
826 void (*handler)(struct packet *);
827 char *type;
828
829 switch (packet->packet_type) {
830 case DHCPOFFER:
832 type = "DHCPOFFER";
833 break;
834 case DHCPNAK:
836 type = "DHCPNACK";
837 break;
838 case DHCPACK:
840 type = "DHCPACK";
841 break;
842 default:
843 return;
844 }
845
846 /* If there's a reject list, make sure this packet's sender isn't
847 on it. */
848 for (ap = packet->interface->client->config->reject_list;
849 ap; ap = ap->next) {
850 if (addr_eq(packet->client_addr, ap->addr)) {
851 note("%s from %s rejected.", type, piaddr(ap->addr));
852 return;
853 }
854 }
855 (*handler)(packet);
856}
#define DHCPNAK
Definition: dhcp.h:167
#define DHCPACK
Definition: dhcp.h:166
#define DHCPOFFER
Definition: dhcp.h:163
void dhcpnak(struct packet *packet)
Definition: dhclient.c:1073
void dhcpack(struct packet *packet)
Definition: dhclient.c:338
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int packet_type
Definition: dhcpd.h:138

Referenced by do_packet(), and START_TEST().

◆ dhcp_option_ev_name()

int dhcp_option_ev_name ( char buf,
size_t  buflen,
struct dhcp_option option 
)

Definition at line 2152 of file dhclient.c.

2153{
2154 int i;
2155
2156 for (i = 0; option->name[i]; i++) {
2157 if (i + 1 == buflen)
2158 return 0;
2159 if (option->name[i] == '-')
2160 buf[i] = '_';
2161 else
2162 buf[i] = option->name[i];
2163 }
2164
2165 buf[i] = 0;
2166 return 1;
2167}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
WCHAR * name
Definition: getopt.h:110

Referenced by priv_script_write_params().

◆ dhcpack()

void dhcpack ( struct packet packet)

Definition at line 338 of file dhclient.c.

339{
341 struct client_lease *lease;
343
344 time(&cur_time);
345
346 /* If we're not receptive to an offer right now, or if the offer
347 has an unrecognizable transaction id, then just drop it. */
348 if (packet->interface->client->xid != packet->raw->xid ||
349 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
350 (memcmp(packet->interface->hw_address.haddr,
351 packet->raw->chaddr, packet->raw->hlen)))
352 return;
353
354 if (ip->client->state != S_REBOOTING &&
355 ip->client->state != S_REQUESTING &&
356 ip->client->state != S_RENEWING &&
357 ip->client->state != S_REBINDING)
358 return;
359
360 note("DHCPACK from %s", piaddr(packet->client_addr));
361
362 lease = packet_to_lease(packet);
363 if (!lease) {
364 note("packet_to_lease failed.");
365 return;
366 }
367
368 ip->client->new = lease;
369
370 /* Stop resending DHCPREQUEST. */
372
373 /* Figure out the lease time. */
374 if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data)
375 ip->client->new->expiry = getULong(
376 ip->client->new->options[DHO_DHCP_LEASE_TIME].data);
377 else
378 ip->client->new->expiry = DHCP_DEFAULT_LEASE_TIME;
379 /* A number that looks negative here is really just very large,
380 because the lease expiry offset is unsigned. */
381 if (ip->client->new->expiry < 0)
382 ip->client->new->expiry = TIME_MAX;
383 /* XXX should be fixed by resetting the client state */
384 if (ip->client->new->expiry < 60)
385 ip->client->new->expiry = 60;
386
387 /* Take the server-provided renewal time if there is one;
388 otherwise figure it out according to the spec. */
389 if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len)
390 ip->client->new->renewal = getULong(
391 ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data);
392 else
393 ip->client->new->renewal = ip->client->new->expiry / 2;
394
395 /* Same deal with the rebind time. */
396 if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len)
397 ip->client->new->rebind = getULong(
398 ip->client->new->options[DHO_DHCP_REBINDING_TIME].data);
399 else
400 ip->client->new->rebind = ip->client->new->renewal +
401 ip->client->new->renewal / 2 + ip->client->new->renewal / 4;
402
403#ifdef __REACTOS__
404 ip->client->new->lease = ip->client->new->expiry;
405 ip->client->new->obtained = cur_time;
406#endif
407 ip->client->new->expiry += cur_time;
408 /* Lease lengths can never be negative. */
409 if (ip->client->new->expiry < cur_time)
410 ip->client->new->expiry = TIME_MAX;
411 ip->client->new->renewal += cur_time;
412 if (ip->client->new->renewal < cur_time)
413 ip->client->new->renewal = TIME_MAX;
414 ip->client->new->rebind += cur_time;
415 if (ip->client->new->rebind < cur_time)
416 ip->client->new->rebind = TIME_MAX;
417
418 bind_lease(ip);
419}
void cancel_timeout(void(*where)(void *), void *what)
Definition: dispatch.c:316
u_int32_t getULong(unsigned char *data)
Definition: util.c:96
#define TIME_MAX
Definition: dhclient.c:90
struct client_lease * packet_to_lease(struct packet *packet)
Definition: dhclient.c:979
void bind_lease(struct interface_info *ip)
Definition: dhclient.c:707
@ S_REBOOTING
Definition: dhcpd.h:172
@ S_RENEWING
Definition: dhcpd.h:177
@ S_REBINDING
Definition: dhcpd.h:178
@ S_REQUESTING
Definition: dhcpd.h:175
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
#define DHCP_DEFAULT_LEASE_TIME
Definition: rosdhcp.h:34

Referenced by dhcp().

◆ dhcpnak()

void dhcpnak ( struct packet packet)

Definition at line 1073 of file dhclient.c.

1074{
1075 struct interface_info *ip = packet->interface;
1076
1077 /* If we're not receptive to an offer right now, or if the offer
1078 has an unrecognizable transaction id, then just drop it. */
1079 if (packet->interface->client->xid != packet->raw->xid ||
1080 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
1081 (memcmp(packet->interface->hw_address.haddr,
1082 packet->raw->chaddr, packet->raw->hlen)))
1083 return;
1084
1085 if (ip->client->state != S_REBOOTING &&
1086 ip->client->state != S_REQUESTING &&
1087 ip->client->state != S_RENEWING &&
1088 ip->client->state != S_REBINDING)
1089 return;
1090
1091 note("DHCPNAK from %s", piaddr(packet->client_addr));
1092
1093 if (!ip->client->active) {
1094 note("DHCPNAK with no active lease.\n");
1095 return;
1096 }
1097
1098 free_client_lease(ip->client->active);
1099 ip->client->active = NULL;
1100
1101 /* Stop sending DHCPREQUEST packets... */
1103
1104 ip->client->state = S_INIT;
1105 state_init(ip);
1106}
void state_init(void *ipp)
Definition: dhclient.c:210
@ S_INIT
Definition: dhcpd.h:173

Referenced by dhcp().

◆ dhcpoffer()

void dhcpoffer ( struct packet packet)

Definition at line 859 of file dhclient.c.

860{
862 struct client_lease *lease, *lp;
863 int i;
864 int arp_timeout_needed = 0;
865 time_t stop_selecting;
867 "DHCPOFFER" : "BOOTREPLY";
869
870 time(&cur_time);
871
872 /* If we're not receptive to an offer right now, or if the offer
873 has an unrecognizable transaction id, then just drop it. */
874 if (ip->client->state != S_SELECTING ||
875 packet->interface->client->xid != packet->raw->xid ||
876 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
877 (memcmp(packet->interface->hw_address.haddr,
878 packet->raw->chaddr, packet->raw->hlen)))
879 return;
880
881 note("%s from %s", name, piaddr(packet->client_addr));
882
883
884 /* If this lease doesn't supply the minimum required parameters,
885 blow it off. */
886 for (i = 0; ip->client->config->required_options[i]; i++) {
887 if (!packet->options[ip->client->config->
888 required_options[i]].len) {
889 note("%s isn't satisfactory.", name);
890 return;
891 }
892 }
893
894 /* If we've already seen this lease, don't record it again. */
895 for (lease = ip->client->offered_leases;
896 lease; lease = lease->next) {
897 if (lease->address.len == sizeof(packet->raw->yiaddr) &&
898 !memcmp(lease->address.iabuf,
899 &packet->raw->yiaddr, lease->address.len)) {
900 debug("%s already seen.", name);
901 return;
902 }
903 }
904
905 lease = packet_to_lease(packet);
906 if (!lease) {
907 note("packet_to_lease failed.");
908 return;
909 }
910
911 /* If this lease was acquired through a BOOTREPLY, record that
912 fact. */
914 lease->is_bootp = 1;
915
916 /* Record the medium under which this lease was offered. */
917 lease->medium = ip->client->medium;
918
919 /* Send out an ARP Request for the offered IP address. */
920 if( !check_arp( ip, lease ) ) {
921 note("Arp check failed\n");
922 return;
923 }
924
925 /* Figure out when we're supposed to stop selecting. */
926 stop_selecting =
927 ip->client->first_sending + ip->client->config->select_interval;
928
929 /* If this is the lease we asked for, put it at the head of the
930 list, and don't mess with the arp request timeout. */
931 if (lease->address.len == ip->client->requested_address.len &&
932 !memcmp(lease->address.iabuf,
933 ip->client->requested_address.iabuf,
934 ip->client->requested_address.len)) {
935 lease->next = ip->client->offered_leases;
936 ip->client->offered_leases = lease;
937 } else {
938 /* If we already have an offer, and arping for this
939 offer would take us past the selection timeout,
940 then don't extend the timeout - just hope for the
941 best. */
942 if (ip->client->offered_leases &&
943 (cur_time + arp_timeout_needed) > stop_selecting)
944 arp_timeout_needed = 0;
945
946 /* Put the lease at the end of the list. */
947 lease->next = NULL;
948 if (!ip->client->offered_leases)
949 ip->client->offered_leases = lease;
950 else {
951 for (lp = ip->client->offered_leases; lp->next;
952 lp = lp->next)
953 ; /* nothing */
954 lp->next = lease;
955 }
956 }
957
958 /* If we're supposed to stop selecting before we've had time
959 to wait for the ARPREPLY, add some delay to wait for
960 the ARPREPLY. */
961 if (stop_selecting - cur_time < arp_timeout_needed)
962 stop_selecting = cur_time + arp_timeout_needed;
963
964 /* If the selecting interval has expired, go immediately to
965 state_selecting(). Otherwise, time out into
966 state_selecting at the select interval. */
967 if (stop_selecting <= 0)
969 else {
970 add_timeout(stop_selecting, state_selecting, ip);
972 }
973}
void send_discover(void *ipp)
Definition: dhclient.c:1113
void state_selecting(void *ipp)
Definition: dhclient.c:257
int check_arp(struct interface_info *ip, struct client_lease *lp)
Definition: dhclient.c:137
@ S_SELECTING
Definition: dhcpd.h:174
#define debug(msg)
Definition: key_call.c:71
struct string_list * medium
Definition: dhcpd.h:164
struct iaddr address
Definition: dhcpd.h:156
unsigned int is_bootp
Definition: dhcpd.h:166
struct client_lease * next
Definition: dhcpd.h:154
Definition: name.c:39
struct option_data options[256]
Definition: dhcpd.h:144

Referenced by bootp(), and dhcp().

◆ fork_privchld()

int fork_privchld ( int  ,
int   
)

◆ free_client_lease()

void free_client_lease ( struct client_lease lease)

Definition at line 1900 of file dhclient.c.

1901{
1902 int i;
1903
1904 if (lease->server_name)
1905 free(lease->server_name);
1906 if (lease->filename)
1907 free(lease->filename);
1908 for (i = 0; i < 256; i++) {
1909 if (lease->options[i].len)
1910 free(lease->options[i].data);
1911 }
1912 free(lease);
1913}
#define free
Definition: debug_ros.c:5
struct option_data options[256]
Definition: dhcpd.h:167
char * filename
Definition: dhcpd.h:163
char * server_name
Definition: dhcpd.h:157

Referenced by bind_lease(), dhcpnak(), packet_to_lease(), state_selecting(), and unbind_lease().

◆ init_client()

int init_client ( void  )

Definition at line 111 of file dhclient.c.

112{
113 ApiInit();
114 AdapterInit();
115
116 tzset();
117
119 sockaddr_broadcast.sin_family = AF_INET;
121 sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
122 inaddr_any.s_addr = INADDR_ANY;
124
125 return 1; // TRUE
126}
void AdapterInit()
Definition: adapter.c:289
VOID ApiInit()
Definition: api.c:18
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *)
Definition: dispatch.c:59
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, int len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
Definition: options.c:635
struct in_addr inaddr_any
Definition: dhclient.c:81
struct sockaddr_in sockaddr_broadcast
Definition: dhclient.c:82
#define REMOTE_PORT
Definition: dhcpd.h:113
#define AF_INET
Definition: tcpip.h:117
#define INADDR_BROADCAST
Definition: inet.h:82
#define INADDR_ANY
Definition: inet.h:80
#define htons(x)
Definition: module.h:215
_CRTIMP void __cdecl tzset(void)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ServiceMain().

◆ ipv4addrs()

int ipv4addrs ( char buf)

Definition at line 2322 of file dhclient.c.

2323{
2324 char *tmp;
2325 struct in_addr jnk;
2326 int i = 0;
2327
2328 note("Input: %s", buf);
2329
2330 do {
2331 tmp = strtok(buf, " ");
2332 note("got %s", tmp);
2333 if( tmp && inet_aton(tmp, &jnk) ) i++;
2334 buf = NULL;
2335 } while( tmp );
2336
2337 return (i);
2338}
#define inet_aton(ap, inp)
Definition: adns_win32.h:161
_ACRTIMP char *__cdecl strtok(char *, const char *)
Definition: string.c:285
Definition: tcpip.h:126

Referenced by check_option().

◆ make_decline()

void make_decline ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1762 of file dhclient.c.

1763{
1764 struct tree_cache *options[256], message_type_tree;
1765 struct tree_cache requested_address_tree;
1766 struct tree_cache server_id_tree, client_id_tree;
1767 unsigned char decline = DHCPDECLINE;
1768 int i;
1769
1770 memset(options, 0, sizeof(options));
1771 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1772
1773 /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */
1775 options[i] = &message_type_tree;
1776 options[i]->value = &decline;
1777 options[i]->len = sizeof(decline);
1778 options[i]->buf_size = sizeof(decline);
1779 options[i]->timeout = 0xFFFFFFFF;
1780
1781 /* Send back the server identifier... */
1783 options[i] = &server_id_tree;
1784 options[i]->value = lease->options[i].data;
1785 options[i]->len = lease->options[i].len;
1786 options[i]->buf_size = lease->options[i].len;
1787 options[i]->timeout = 0xFFFFFFFF;
1788
1789 /* Send back the address we're declining. */
1791 options[i] = &requested_address_tree;
1792 options[i]->value = lease->address.iabuf;
1793 options[i]->len = lease->address.len;
1794 options[i]->buf_size = lease->address.len;
1795 options[i]->timeout = 0xFFFFFFFF;
1796
1797 /* Send the uid if the user supplied one. */
1799 if (ip->client->config->send_options[i].len) {
1800 options[i] = &client_id_tree;
1801 options[i]->value = ip->client->config->send_options[i].data;
1802 options[i]->len = ip->client->config->send_options[i].len;
1803 options[i]->buf_size = ip->client->config->send_options[i].len;
1804 options[i]->timeout = 0xFFFFFFFF;
1805 }
1806
1807
1808 /* Set up the option buffer... */
1809 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1810 options);
1811 if (ip->client->packet_length < BOOTP_MIN_LEN)
1812 ip->client->packet_length = BOOTP_MIN_LEN;
1813
1814 ip->client->packet.op = BOOTREQUEST;
1815 ip->client->packet.htype = ip->hw_address.htype;
1816 ip->client->packet.hlen = ip->hw_address.hlen;
1817 ip->client->packet.hops = 0;
1818 ip->client->packet.xid = ip->client->xid;
1819 ip->client->packet.secs = 0; /* Filled in by send_request. */
1820 ip->client->packet.flags = 0;
1821
1822 /* ciaddr must always be zero. */
1823 memset(&ip->client->packet.ciaddr, 0,
1824 sizeof(ip->client->packet.ciaddr));
1825 memset(&ip->client->packet.yiaddr, 0,
1826 sizeof(ip->client->packet.yiaddr));
1827 memset(&ip->client->packet.siaddr, 0,
1828 sizeof(ip->client->packet.siaddr));
1829 memset(&ip->client->packet.giaddr, 0,
1830 sizeof(ip->client->packet.giaddr));
1831 memcpy(ip->client->packet.chaddr,
1832 ip->hw_address.haddr, ip->hw_address.hlen);
1833}
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, int mms, struct tree_cache **options)
Definition: options.c:199
#define BOOTP_MIN_LEN
Definition: dhcp.h:54
#define BOOTREQUEST
Definition: dhcp.h:78
#define DHCPDECLINE
Definition: dhcp.h:165
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ make_discover()

void make_discover ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1577 of file dhclient.c.

1578{
1579 unsigned char discover = DHCPDISCOVER;
1580 struct tree_cache *options[256];
1581 struct tree_cache option_elements[256];
1582 int i;
1584
1585 memset(option_elements, 0, sizeof(option_elements));
1586 memset(options, 0, sizeof(options));
1587 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1588
1589 /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */
1591 options[i] = &option_elements[i];
1592 options[i]->value = &discover;
1593 options[i]->len = sizeof(discover);
1594 options[i]->buf_size = sizeof(discover);
1595 options[i]->timeout = 0xFFFFFFFF;
1596
1597 /* Request the options we want */
1599 options[i] = &option_elements[i];
1600 options[i]->value = ip->client->config->requested_options;
1601 options[i]->len = ip->client->config->requested_option_count;
1602 options[i]->buf_size =
1603 ip->client->config->requested_option_count;
1604 options[i]->timeout = 0xFFFFFFFF;
1605
1606 /* If we had an address, try to get it again. */
1607 if (lease) {
1608 ip->client->requested_address = lease->address;
1610 options[i] = &option_elements[i];
1611 options[i]->value = lease->address.iabuf;
1612 options[i]->len = lease->address.len;
1613 options[i]->buf_size = lease->address.len;
1614 options[i]->timeout = 0xFFFFFFFF;
1615 } else
1616 ip->client->requested_address.len = 0;
1617
1618 /* Send any options requested in the config file. */
1619 for (i = 0; i < 256; i++)
1620 if (!options[i] &&
1621 ip->client->config->send_options[i].data) {
1622 options[i] = &option_elements[i];
1623 options[i]->value =
1624 ip->client->config->send_options[i].data;
1625 options[i]->len =
1626 ip->client->config->send_options[i].len;
1627 options[i]->buf_size =
1628 ip->client->config->send_options[i].len;
1629 options[i]->timeout = 0xFFFFFFFF;
1630 }
1631
1632 /* Set up the option buffer... */
1633 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1634 options);
1635 if (ip->client->packet_length < BOOTP_MIN_LEN)
1636 ip->client->packet_length = BOOTP_MIN_LEN;
1637
1638 ip->client->packet.op = BOOTREQUEST;
1639 ip->client->packet.htype = ip->hw_address.htype;
1640 ip->client->packet.hlen = ip->hw_address.hlen;
1641 ip->client->packet.hops = 0;
1642 ip->client->packet.xid = RtlRandom(&foo);
1643 ip->client->packet.secs = 0; /* filled in by send_discover. */
1644 ip->client->packet.flags = 0;
1645
1646 memset(&(ip->client->packet.ciaddr),
1647 0, sizeof(ip->client->packet.ciaddr));
1648 memset(&(ip->client->packet.yiaddr),
1649 0, sizeof(ip->client->packet.yiaddr));
1650 memset(&(ip->client->packet.siaddr),
1651 0, sizeof(ip->client->packet.siaddr));
1652 memset(&(ip->client->packet.giaddr),
1653 0, sizeof(ip->client->packet.giaddr));
1654 memcpy(ip->client->packet.chaddr,
1655 ip->hw_address.haddr, ip->hw_address.hlen);
1656}
#define DHCPDISCOVER
Definition: dhcp.h:162
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
uint32_t ULONG
Definition: typedefs.h:59

Referenced by state_init().

◆ make_release()

void make_release ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1836 of file dhclient.c.

1837{
1838 struct tree_cache *options[256], message_type_tree;
1839 struct tree_cache server_id_tree, client_id_tree;
1840 unsigned char release = DHCPRELEASE;
1841 int i;
1842
1843 memset(options, 0, sizeof(options));
1844 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1845
1846 /* Set DHCP_MESSAGE_TYPE to DHCPRELEASE */
1848 options[i] = &message_type_tree;
1849 options[i]->value = &release;
1850 options[i]->len = sizeof(release);
1851 options[i]->buf_size = sizeof(release);
1852 options[i]->timeout = 0xFFFFFFFF;
1853
1854 /* Send back the server identifier... */
1856 options[i] = &server_id_tree;
1857 options[i]->value = lease->options[i].data;
1858 options[i]->len = lease->options[i].len;
1859 options[i]->buf_size = lease->options[i].len;
1860 options[i]->timeout = 0xFFFFFFFF;
1861
1862 /* Send the uid if the user supplied one. */
1864 if (ip->client->config->send_options[i].len)
1865 {
1866 options[i] = &client_id_tree;
1867 options[i]->value = ip->client->config->send_options[i].data;
1868 options[i]->len = ip->client->config->send_options[i].len;
1869 options[i]->buf_size = ip->client->config->send_options[i].len;
1870 options[i]->timeout = 0xFFFFFFFF;
1871 }
1872
1873 /* Set up the option buffer... */
1874 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, options);
1875 if (ip->client->packet_length < BOOTP_MIN_LEN)
1876 ip->client->packet_length = BOOTP_MIN_LEN;
1877
1878 ip->client->packet.op = BOOTREQUEST;
1879 ip->client->packet.htype = ip->hw_address.htype;
1880 ip->client->packet.hlen = ip->hw_address.hlen;
1881 ip->client->packet.hops = 0;
1882 ip->client->packet.xid = 0;
1883 ip->client->packet.secs = 0;
1884 ip->client->packet.flags = 0;
1885
1886 /* ciaddr is the address to be released */
1887 memcpy(&ip->client->packet.ciaddr,
1888 lease->address.iabuf, lease->address.len);
1889 memset(&ip->client->packet.yiaddr, 0,
1890 sizeof(ip->client->packet.yiaddr));
1891 memset(&ip->client->packet.siaddr, 0,
1892 sizeof(ip->client->packet.siaddr));
1893 memset(&ip->client->packet.giaddr, 0,
1894 sizeof(ip->client->packet.giaddr));
1895 memcpy(ip->client->packet.chaddr,
1896 ip->hw_address.haddr, ip->hw_address.hlen);
1897}
#define DHCPRELEASE
Definition: dhcp.h:168

Referenced by state_release().

◆ make_request()

void make_request ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1660 of file dhclient.c.

1661{
1662 unsigned char request = DHCPREQUEST;
1663 struct tree_cache *options[256];
1664 struct tree_cache option_elements[256];
1665 int i;
1666
1667 memset(options, 0, sizeof(options));
1668 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1669
1670 /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */
1672 options[i] = &option_elements[i];
1673 options[i]->value = &request;
1674 options[i]->len = sizeof(request);
1675 options[i]->buf_size = sizeof(request);
1676 options[i]->timeout = 0xFFFFFFFF;
1677
1678 /* Request the options we want */
1680 options[i] = &option_elements[i];
1681 options[i]->value = ip->client->config->requested_options;
1682 options[i]->len = ip->client->config->requested_option_count;
1683 options[i]->buf_size =
1684 ip->client->config->requested_option_count;
1685 options[i]->timeout = 0xFFFFFFFF;
1686
1687 /* If we are requesting an address that hasn't yet been assigned
1688 to us, use the DHCP Requested Address option. */
1689 if (ip->client->state == S_REQUESTING) {
1690 /* Send back the server identifier... */
1692 options[i] = &option_elements[i];
1693 options[i]->value = lease->options[i].data;
1694 options[i]->len = lease->options[i].len;
1695 options[i]->buf_size = lease->options[i].len;
1696 options[i]->timeout = 0xFFFFFFFF;
1697 }
1698 if (ip->client->state == S_REQUESTING ||
1699 ip->client->state == S_REBOOTING) {
1700 ip->client->requested_address = lease->address;
1702 options[i] = &option_elements[i];
1703 options[i]->value = lease->address.iabuf;
1704 options[i]->len = lease->address.len;
1705 options[i]->buf_size = lease->address.len;
1706 options[i]->timeout = 0xFFFFFFFF;
1707 } else
1708 ip->client->requested_address.len = 0;
1709
1710 /* Send any options requested in the config file. */
1711 for (i = 0; i < 256; i++)
1712 if (!options[i] &&
1713 ip->client->config->send_options[i].data) {
1714 options[i] = &option_elements[i];
1715 options[i]->value =
1716 ip->client->config->send_options[i].data;
1717 options[i]->len =
1718 ip->client->config->send_options[i].len;
1719 options[i]->buf_size =
1720 ip->client->config->send_options[i].len;
1721 options[i]->timeout = 0xFFFFFFFF;
1722 }
1723
1724 /* Set up the option buffer... */
1725 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1726 options);
1727 if (ip->client->packet_length < BOOTP_MIN_LEN)
1728 ip->client->packet_length = BOOTP_MIN_LEN;
1729
1730 ip->client->packet.op = BOOTREQUEST;
1731 ip->client->packet.htype = ip->hw_address.htype;
1732 ip->client->packet.hlen = ip->hw_address.hlen;
1733 ip->client->packet.hops = 0;
1734 ip->client->packet.xid = ip->client->xid;
1735 ip->client->packet.secs = 0; /* Filled in by send_request. */
1736
1737 /* If we own the address we're requesting, put it in ciaddr;
1738 otherwise set ciaddr to zero. */
1739 if (ip->client->state == S_BOUND ||
1740 ip->client->state == S_RENEWING ||
1741 ip->client->state == S_REBINDING) {
1742 memcpy(&ip->client->packet.ciaddr,
1743 lease->address.iabuf, lease->address.len);
1744 ip->client->packet.flags = 0;
1745 } else {
1746 memset(&ip->client->packet.ciaddr, 0,
1747 sizeof(ip->client->packet.ciaddr));
1748 ip->client->packet.flags = 0;
1749 }
1750
1751 memset(&ip->client->packet.yiaddr, 0,
1752 sizeof(ip->client->packet.yiaddr));
1753 memset(&ip->client->packet.siaddr, 0,
1754 sizeof(ip->client->packet.siaddr));
1755 memset(&ip->client->packet.giaddr, 0,
1756 sizeof(ip->client->packet.giaddr));
1757 memcpy(ip->client->packet.chaddr,
1758 ip->hw_address.haddr, ip->hw_address.hlen);
1759}
#define DHCPREQUEST
Definition: dhcp.h:164
Definition: tftpd.h:86

Referenced by state_bound(), state_reboot(), and state_selecting().

◆ option_as_string()

char * option_as_string ( unsigned int  code,
unsigned char data,
int  len 
)

Definition at line 2342 of file dhclient.c.

2343{
2344 static char optbuf[32768]; /* XXX */
2345 char *op = optbuf;
2346 int opleft = sizeof(optbuf);
2347 unsigned char *dp = data;
2348
2349 if (code > 255)
2350 error("option_as_string: bad code %d", code);
2351
2352 for (; dp < data + len; dp++) {
2353 if (!isascii(*dp) || !isprint(*dp)) {
2354 if (dp + 1 != data + len || *dp != 0) {
2355 _snprintf(op, opleft, "\\%03o", *dp);
2356 op += 4;
2357 opleft -= 4;
2358 }
2359 } else if (*dp == '"' || *dp == '\'' || *dp == '$' ||
2360 *dp == '`' || *dp == '\\') {
2361 *op++ = '\\';
2362 *op++ = *dp;
2363 opleft -= 2;
2364 } else {
2365 *op++ = *dp;
2366 opleft--;
2367 }
2368 }
2369 if (opleft < 1)
2370 goto toobig;
2371 *op = 0;
2372 return optbuf;
2373toobig:
2374 warning("dhcp option too large");
2375 return "<error>";
2376}
#define isprint(c)
Definition: acclib.h:73
UINT op
Definition: effect.c:236
static int __cdecl _snprintf(char *buffer, size_t size, const char *format,...) __WINE_CRT_PRINTF_ATTR(3
Definition: stdio.h:507
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
#define isascii
Definition: ctype.h:742
Definition: inflate.c:139

Referenced by check_option().

◆ packet_to_lease()

struct client_lease * packet_to_lease ( struct packet packet)

Definition at line 979 of file dhclient.c.

980{
981 struct client_lease *lease;
982 int i;
983
984 lease = malloc(sizeof(struct client_lease));
985
986 if (!lease) {
987 warning("dhcpoffer: no memory to record lease.");
988 return (NULL);
989 }
990
991 memset(lease, 0, sizeof(*lease));
992
993 /* Copy the lease options. */
994 for (i = 0; i < 256; i++) {
995 if (packet->options[i].len) {
996 lease->options[i].data =
997 malloc(packet->options[i].len + 1);
998 if (!lease->options[i].data) {
999 warning("dhcpoffer: no memory for option %d", i);
1000 free_client_lease(lease);
1001 return (NULL);
1002 } else {
1003 memcpy(lease->options[i].data,
1004 packet->options[i].data,
1005 packet->options[i].len);
1006 lease->options[i].len =
1007 packet->options[i].len;
1008 lease->options[i].data[lease->options[i].len] =
1009 0;
1010 }
1011 if (!check_option(lease,i)) {
1012 /* ignore a bogus lease offer */
1013 warning("Invalid lease option - ignoring offer");
1014 free_client_lease(lease);
1015 return (NULL);
1016 }
1017 }
1018 }
1019
1020 lease->address.len = sizeof(packet->raw->yiaddr);
1021 memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len);
1022#ifdef __REACTOS__
1023 if (packet->raw->siaddr.S_un.S_addr == 0)
1024 {
1025 lease->serveraddress.len = packet->client_addr.len;
1026 memcpy(lease->serveraddress.iabuf, &packet->client_addr.iabuf, packet->client_addr.len);
1027 }
1028 else
1029 {
1030 lease->serveraddress.len = sizeof(packet->raw->siaddr);
1031 memcpy(lease->serveraddress.iabuf, &packet->raw->siaddr, lease->serveraddress.len);
1032 }
1033#endif
1034
1035 /* If the server name was filled out, copy it. */
1037 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) &&
1038 packet->raw->sname[0]) {
1039 lease->server_name = malloc(DHCP_SNAME_LEN + 1);
1040 if (!lease->server_name) {
1041 warning("dhcpoffer: no memory for server name.");
1042 free_client_lease(lease);
1043 return (NULL);
1044 }
1045 memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN);
1046 lease->server_name[DHCP_SNAME_LEN]='\0';
1047 if (!res_hnok(lease->server_name) ) {
1048 warning("Bogus server name %s", lease->server_name );
1049 free_client_lease(lease);
1050 return (NULL);
1051 }
1052
1053 }
1054
1055 /* Ditto for the filename. */
1057 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) &&
1058 packet->raw->file[0]) {
1059 /* Don't count on the NUL terminator. */
1060 lease->filename = malloc(DHCP_FILE_LEN + 1);
1061 if (!lease->filename) {
1062 warning("dhcpoffer: no memory for filename.");
1063 free_client_lease(lease);
1064 return (NULL);
1065 }
1066 memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN);
1067 lease->filename[DHCP_FILE_LEN]='\0';
1068 }
1069 return lease;
1070}
#define DHCP_SNAME_LEN
Definition: dhcp.h:46
#define DHCP_FILE_LEN
Definition: dhcp.h:47
#define malloc
Definition: debug_ros.c:4
int check_option(struct client_lease *l, int option)
Definition: dhclient.c:2198

Referenced by dhcpack(), and dhcpoffer().

◆ priv_script_init()

void priv_script_init ( struct interface_info ip,
char reason,
char medium 
)

Definition at line 2006 of file dhclient.c.

2007{
2008 if (ip) {
2009 // XXX Do we need to do anything?
2010 }
2011}

◆ priv_script_write_params()

void priv_script_write_params ( struct interface_info ip,
char prefix,
struct client_lease lease 
)

Definition at line 2014 of file dhclient.c.

2015{
2016 u_int8_t dbuf[1500];
2017 int i, len = 0;
2018
2019#if 0
2020 script_set_env(ip->client, prefix, "ip_address",
2021 piaddr(lease->address));
2022#endif
2023
2024 if (lease->options[DHO_SUBNET_MASK].len &&
2025 (lease->options[DHO_SUBNET_MASK].len <
2026 sizeof(lease->address.iabuf))) {
2027 struct iaddr netmask, subnet, broadcast;
2028
2029 memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data,
2030 lease->options[DHO_SUBNET_MASK].len);
2031 netmask.len = lease->options[DHO_SUBNET_MASK].len;
2032
2033 subnet = subnet_number(lease->address, netmask);
2034 if (subnet.len) {
2035#if 0
2036 script_set_env(ip->client, prefix, "network_number",
2037 piaddr(subnet));
2038#endif
2039 if (!lease->options[DHO_BROADCAST_ADDRESS].len) {
2040 broadcast = broadcast_addr(subnet, netmask);
2041 if (broadcast.len)
2042#if 0
2043 script_set_env(ip->client, prefix,
2044 "broadcast_address",
2045 piaddr(broadcast));
2046#else
2047 ;
2048#endif
2049 }
2050 }
2051 }
2052
2053#if 0
2054 if (lease->filename)
2055 script_set_env(ip->client, prefix, "filename", lease->filename);
2056 if (lease->server_name)
2057 script_set_env(ip->client, prefix, "server_name",
2058 lease->server_name);
2059#endif
2060
2061 for (i = 0; i < 256; i++) {
2062 u_int8_t *dp = NULL;
2063
2064 if (ip->client->config->defaults[i].len) {
2065 if (lease->options[i].len) {
2066 switch (
2067 ip->client->config->default_actions[i]) {
2068 case ACTION_DEFAULT:
2069 dp = lease->options[i].data;
2070 len = lease->options[i].len;
2071 break;
2072 case ACTION_SUPERSEDE:
2073supersede:
2074 dp = ip->client->
2075 config->defaults[i].data;
2076 len = ip->client->
2077 config->defaults[i].len;
2078 break;
2079 case ACTION_PREPEND:
2080 len = ip->client->
2081 config->defaults[i].len +
2082 lease->options[i].len;
2083 if (len >= sizeof(dbuf)) {
2084 warning("no space to %s %s",
2085 "prepend option",
2087 goto supersede;
2088 }
2089 dp = dbuf;
2090 memcpy(dp,
2091 ip->client->
2092 config->defaults[i].data,
2093 ip->client->
2094 config->defaults[i].len);
2095 memcpy(dp + ip->client->
2096 config->defaults[i].len,
2097 lease->options[i].data,
2098 lease->options[i].len);
2099 dp[len] = '\0';
2100 break;
2101 case ACTION_APPEND:
2102 len = ip->client->
2103 config->defaults[i].len +
2104 lease->options[i].len + 1;
2105 if (len > sizeof(dbuf)) {
2106 warning("no space to %s %s",
2107 "append option",
2109 goto supersede;
2110 }
2111 dp = dbuf;
2112 memcpy(dp,
2113 lease->options[i].data,
2114 lease->options[i].len);
2115 memcpy(dp + lease->options[i].len,
2116 ip->client->
2117 config->defaults[i].data,
2118 ip->client->
2119 config->defaults[i].len);
2120 dp[len-1] = '\0';
2121 }
2122 } else {
2123 dp = ip->client->
2124 config->defaults[i].data;
2125 len = ip->client->
2126 config->defaults[i].len;
2127 }
2128 } else if (lease->options[i].len) {
2129 len = lease->options[i].len;
2130 dp = lease->options[i].data;
2131 } else {
2132 len = 0;
2133 }
2134#if 0
2135 if (len) {
2136 char name[256];
2137
2138 if (dhcp_option_ev_name(name, sizeof(name),
2139 &dhcp_options[i]))
2140 script_set_env(ip->client, prefix, name,
2141 pretty_print_option(i, dp, len, 0, 0));
2142 }
2143#endif
2144 }
2145#if 0
2146 snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry);
2147 script_set_env(ip->client, prefix, "expiry", tbuf);
2148#endif
2149}
struct dhcp_option dhcp_options[256]
Definition: tables.c:68
struct iaddr broadcast_addr(struct iaddr addr, struct iaddr mask)
Definition: util.c:178
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
Definition: util.c:183
int dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
Definition: dhclient.c:2152
void script_set_env(struct client_state *, const char *, const char *, const char *)
unsigned char u_int8_t
Definition: rosdhcp.h:37
time_t expiry
Definition: dhcpd.h:155
Definition: dhcpd.h:125
Character const *const prefix
Definition: tempnam.cpp:195
static const u8_t broadcast[6]
Definition: test_dhcp.c:23
#define snprintf
Definition: wintirpc.h:48

◆ res_hnok()

int res_hnok ( const char dn)

Definition at line 2293 of file dhclient.c.

2294{
2295 int pch = PERIOD, ch = *dn++;
2296
2297 while (ch != '\0') {
2298 int nch = *dn++;
2299
2300 if (periodchar(ch)) {
2301 ;
2302 } else if (periodchar(pch)) {
2303 if (!borderchar(ch))
2304 return (0);
2305 } else if (periodchar(nch) || nch == '\0') {
2306 if (!borderchar(ch))
2307 return (0);
2308 } else {
2309 if (!middlechar(ch))
2310 return (0);
2311 }
2312 pch = ch, ch = nch;
2313 }
2314 return (1);
2315}
#define middlechar(c)
Definition: dhclient.c:68
#define periodchar(c)
Definition: dhclient.c:61
#define borderchar(c)
Definition: dhclient.c:67
#define PERIOD
Definition: dhclient.c:58
unsigned char ch[4][2]
Definition: console.c:118
int nch
Definition: scanf.h:201
#define pch(ap)
Definition: match.c:418

Referenced by check_option(), and packet_to_lease().

◆ reset_adapter()

void reset_adapter ( PDHCP_ADAPTER  Adapter)

Definition at line 654 of file dhclient.c.

654 {
655 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
656 CHAR IpAddress[] = "0.0.0.0";
657 CHAR SubnetMask[] = "255.0.0.0";
658 CHAR Server[] = "255.255.255.255";
659 HKEY hkey;
660 DWORD lease;
661 time_t cur_time, new_time;
662
663 time(&cur_time);
664
665 strcat(Buffer, Adapter->DhclientInfo.name);
667 hkey = NULL;
668
669 if( Adapter->NteContext )
670 {
671 DeleteIPAddress( Adapter->NteContext );
672 Adapter->NteContext = 0;
673 }
674
675 if (hkey) {
676 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)IpAddress, strlen(IpAddress)+1);
677 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask)+1);
678 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server)+1);
679
680 lease = 3600;
681 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
682 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
683 new_time = cur_time + lease;
684 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
685 new_time = cur_time + (lease / 2);
686 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
687 new_time = cur_time + lease - (lease / 8);
688 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
689 DWORD dwAddressType = 0;
690 RegSetValueExA(hkey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
691 }
692
693 if( Adapter->RouterMib.dwForwardNextHop ) {
694 DeleteIpForwardEntry( &Adapter->RouterMib );
695 }
696
697 if (hkey) {
698 RegDeleteValueA(hkey, "DhcpDefaultGateway");
699 }
700
701 if (hkey)
702 RegCloseKey(hkey);
703}
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
#define REG_SZ
Definition: layer.c:22
#define KEY_WRITE
Definition: nt_native.h:1034
char CHAR
Definition: pedump.c:57
#define REG_DWORD
Definition: sdbapi.c:615
strcat
Definition: string.h:92
static void Server(int port)
Definition: srltest.c:69
ULONG NteContext
Definition: rosdhcp.h:85
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:82
struct interface_info DhclientInfo
Definition: rosdhcp.h:86
DWORD dwForwardNextHop
Definition: ipmib.h:74
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by unbind_lease().

◆ rewrite_client_leases()

void rewrite_client_leases ( struct interface_info ifi)

Definition at line 1918 of file dhclient.c.

1919{
1920 struct client_lease *lp;
1921
1922 if (!leaseFile) {
1924 if (!leaseFile)
1925 error("can't create %s", path_dhclient_db);
1926 } else {
1929 }
1930
1931 for (lp = ifi->client->leases; lp; lp = lp->next)
1932 write_client_lease(ifi, lp, 1);
1933 if (ifi->client->active)
1934 write_client_lease(ifi, ifi->client->active, 1);
1935
1937}
char * path_dhclient_db
Definition: dhclient.c:74
void write_client_lease(struct interface_info *ip, struct client_lease *lease, int rewrite)
Definition: dhclient.c:1940
FILE * leaseFile
Definition: dhclient.c:1915
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
void CDECL rewind(FILE *file)
Definition: file.c:1712
int CDECL fflush(FILE *file)
Definition: file.c:1182
struct client_state * client
Definition: dhcpd.h:241

Referenced by write_client_lease().

◆ send_decline()

void send_decline ( void ipp)

Definition at line 1538 of file dhclient.c.

1539{
1540 struct interface_info *ip = ipp;
1541
1542 note("DHCPDECLINE on %s to %s port %d", ip->name,
1543 inet_ntoa(sockaddr_broadcast.sin_addr),
1544 ntohs(sockaddr_broadcast.sin_port));
1545
1546 /* Send out a packet. */
1547 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1549}
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:160
#define ntohs(x)
Definition: module.h:210
ssize_t send_packet(struct interface_info *ip, struct dhcp_packet *p, size_t size, struct in_addr addr, struct sockaddr_in *broadcast, struct hardware *hardware)
Definition: socket.c:9

◆ send_discover()

void send_discover ( void ipp)

Definition at line 1113 of file dhclient.c.

1114{
1115 struct interface_info *ip = ipp;
1116 int interval, increase = 1;
1118
1119 DH_DbgPrint(MID_TRACE,("Doing discover on interface %p\n",ip));
1120
1121 time(&cur_time);
1122
1123 /* Figure out how long it's been since we started transmitting. */
1124 interval = cur_time - ip->client->first_sending;
1125
1126 /* If we're past the panic timeout, call the script and tell it
1127 we haven't found anything for this interface yet. */
1128 if (interval > ip->client->config->timeout) {
1129 state_panic(ip);
1130 ip->client->first_sending = cur_time;
1131 }
1132
1133 /* If we're selecting media, try the whole list before doing
1134 the exponential backoff, but if we've already received an
1135 offer, stop looping, because we obviously have it right. */
1136 if (!ip->client->offered_leases &&
1137 ip->client->config->media) {
1138 int fail = 0;
1139
1140 if (ip->client->medium) {
1141 ip->client->medium = ip->client->medium->next;
1142 increase = 0;
1143 }
1144 if (!ip->client->medium) {
1145 if (fail)
1146 error("No valid media types for %s!", ip->name);
1147 ip->client->medium = ip->client->config->media;
1148 increase = 1;
1149 }
1150
1151 note("Trying medium \"%s\" %d", ip->client->medium->string,
1152 increase);
1153 /* XXX Support other media types eventually */
1154 }
1155
1156 /*
1157 * If we're supposed to increase the interval, do so. If it's
1158 * currently zero (i.e., we haven't sent any packets yet), set
1159 * it to one; otherwise, add to it a random number between zero
1160 * and two times itself. On average, this means that it will
1161 * double with every transmission.
1162 */
1163 if (increase) {
1164 if (!ip->client->interval)
1165 ip->client->interval =
1166 ip->client->config->initial_interval;
1167 else {
1168 ip->client->interval += (rand() >> 2) %
1169 (2 * ip->client->interval);
1170 }
1171
1172 /* Don't backoff past cutoff. */
1173 if (ip->client->interval >
1174 ip->client->config->backoff_cutoff)
1175 ip->client->interval =
1176 ((ip->client->config->backoff_cutoff / 2)
1177 + ((rand() >> 2) %
1178 ip->client->config->backoff_cutoff));
1179 } else if (!ip->client->interval)
1180 ip->client->interval =
1181 ip->client->config->initial_interval;
1182
1183 /* If the backoff would take us to the panic timeout, just use that
1184 as the interval. */
1185 if (cur_time + ip->client->interval >
1186 ip->client->first_sending + ip->client->config->timeout)
1187 ip->client->interval =
1188 (ip->client->first_sending +
1189 ip->client->config->timeout) - cur_time + 1;
1190
1191 /* Record the number of seconds since we started sending. */
1192 if (interval < 65536)
1193 ip->client->packet.secs = htons(interval);
1194 else
1195 ip->client->packet.secs = htons(65535);
1196 ip->client->secs = ip->client->packet.secs;
1197
1198 note("DHCPDISCOVER on %s to %s port %d interval %ld",
1199 ip->name, inet_ntoa(sockaddr_broadcast.sin_addr),
1200 ntohs(sockaddr_broadcast.sin_port), (long int)ip->client->interval);
1201
1202 /* Send out a packet. */
1203 (void)send_packet(ip, &ip->client->packet, ip->client->packet_length,
1205
1206 DH_DbgPrint(MID_TRACE,("discover timeout: now %x -> then %x\n",
1207 cur_time, cur_time + ip->client->interval));
1208
1209 add_timeout(cur_time + ip->client->interval, send_discover, ip);
1210}
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
void state_panic(void *ipp)
Definition: dhclient.c:1219
_ACRTIMP int __cdecl rand(void)
Definition: misc.c:59
static void increase(int &a_)

Referenced by dhcpoffer(), send_discover(), state_init(), and state_selecting().

◆ send_release()

void send_release ( void ipp)

Definition at line 1552 of file dhclient.c.

1553{
1554 struct interface_info *ip = ipp;
1555 struct sockaddr_in destination;
1556 struct in_addr from;
1557
1558 memset(&destination, 0, sizeof(destination));
1559 memcpy(&destination.sin_addr.s_addr,
1560 ip->client->destination.iabuf,
1561 sizeof(destination.sin_addr.s_addr));
1562 destination.sin_port = htons(REMOTE_PORT);
1563 destination.sin_family = AF_INET;
1564
1565 memcpy(&from, ip->client->active->address.iabuf,
1566 sizeof(from));
1567
1568 note("DHCPRELEASE on %s to %s port %d", ip->name,
1569 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1570
1571 /* Send out a packet. */
1572 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1573 from, &destination, NULL);
1574}
CardRegion * from
Definition: spigame.cpp:19

Referenced by state_release().

◆ send_request()

void send_request ( void ipp)

Definition at line 1409 of file dhclient.c.

1410{
1411 struct interface_info *ip = ipp;
1412 struct sockaddr_in destination;
1413 struct in_addr from;
1414 int interval;
1416
1417 time(&cur_time);
1418
1419 /* Figure out how long it's been since we started transmitting. */
1420 interval = cur_time - ip->client->first_sending;
1421
1422 /* If we're in the INIT-REBOOT or REQUESTING state and we're
1423 past the reboot timeout, go to INIT and see if we can
1424 DISCOVER an address... */
1425 /* XXX In the INIT-REBOOT state, if we don't get an ACK, it
1426 means either that we're on a network with no DHCP server,
1427 or that our server is down. In the latter case, assuming
1428 that there is a backup DHCP server, DHCPDISCOVER will get
1429 us a new address, but we could also have successfully
1430 reused our old address. In the former case, we're hosed
1431 anyway. This is not a win-prone situation. */
1432 if ((ip->client->state == S_REBOOTING ||
1433 ip->client->state == S_REQUESTING) &&
1434 interval > ip->client->config->reboot_timeout) {
1435 ip->client->state = S_INIT;
1437 state_init(ip);
1438 return;
1439 }
1440
1441 /* If we're in the reboot state, make sure the media is set up
1442 correctly. */
1443 if (ip->client->state == S_REBOOTING &&
1444 !ip->client->medium &&
1445 ip->client->active->medium ) {
1446 /* If the medium we chose won't fly, go to INIT state. */
1447 /* XXX Nothing for now */
1448
1449 /* Record the medium. */
1450 ip->client->medium = ip->client->active->medium;
1451 }
1452
1453 /* If the lease has expired, relinquish the address and go back
1454 to the INIT state. */
1455 if (ip->client->state != S_REQUESTING &&
1456 cur_time > ip->client->active->expiry) {
1457 PDHCP_ADAPTER Adapter = AdapterFindInfo( ip );
1458 /* Run the client script with the new parameters. */
1459 /* No script actions necessary in the expiry case */
1460 /* Now do a preinit on the interface so that we can
1461 discover a new address. */
1462
1463 if( Adapter )
1464 {
1465 DeleteIPAddress( Adapter->NteContext );
1466 Adapter->NteContext = 0;
1467 }
1468
1469 ip->client->state = S_INIT;
1470 state_init(ip);
1471 return;
1472 }
1473
1474 /* Do the exponential backoff... */
1475 if (!ip->client->interval)
1476 ip->client->interval = ip->client->config->initial_interval;
1477 else
1478 ip->client->interval += ((rand() >> 2) %
1479 (2 * ip->client->interval));
1480
1481 /* Don't backoff past cutoff. */
1482 if (ip->client->interval >
1483 ip->client->config->backoff_cutoff)
1484 ip->client->interval =
1485 ((ip->client->config->backoff_cutoff / 2) +
1486 ((rand() >> 2) % ip->client->interval));
1487
1488 /* If the backoff would take us to the expiry time, just set the
1489 timeout to the expiry time. */
1490 if (ip->client->state != S_REQUESTING &&
1491 cur_time + ip->client->interval >
1492 ip->client->active->expiry)
1493 ip->client->interval =
1494 ip->client->active->expiry - cur_time + 1;
1495
1496 /* If the lease T2 time has elapsed, or if we're not yet bound,
1497 broadcast the DHCPREQUEST rather than unicasting. */
1498 memset(&destination, 0, sizeof(destination));
1499 if (ip->client->state == S_REQUESTING ||
1500 ip->client->state == S_REBOOTING ||
1501 cur_time > ip->client->active->rebind)
1502 destination.sin_addr.s_addr = INADDR_BROADCAST;
1503 else
1504 memcpy(&destination.sin_addr.s_addr,
1505 ip->client->destination.iabuf,
1506 sizeof(destination.sin_addr.s_addr));
1507 destination.sin_port = htons(REMOTE_PORT);
1508 destination.sin_family = AF_INET;
1509// destination.sin_len = sizeof(destination);
1510
1511 if (ip->client->state != S_REQUESTING)
1512 memcpy(&from, ip->client->active->address.iabuf,
1513 sizeof(from));
1514 else
1515 from.s_addr = INADDR_ANY;
1516
1517 /* Record the number of seconds since we started sending. */
1518 if (ip->client->state == S_REQUESTING)
1519 ip->client->packet.secs = ip->client->secs;
1520 else {
1521 if (interval < 65536)
1522 ip->client->packet.secs = htons(interval);
1523 else
1524 ip->client->packet.secs = htons(65535);
1525 }
1526
1527 note("DHCPREQUEST on %s to %s port %d", ip->name,
1528 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1529
1530 /* Send out a packet. */
1531 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1532 from, &destination, NULL);
1533
1534 add_timeout(cur_time + ip->client->interval, send_request, ip);
1535}

◆ set_domain()

void set_domain ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 483 of file dhclient.c.

485{
486 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
487 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
488 HKEY RegKey1, RegKey2;
489
490 strcat(Buffer1, Adapter->DhclientInfo.name);
491
492 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
493 {
494 return;
495 }
496
497 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
498 {
499 RegCloseKey(RegKey1);
500 return;
501 }
502
503 if (new_lease->options[DHO_DOMAIN_NAME].len)
504 {
505 DH_DbgPrint(MID_TRACE, ("Setting DhcpDomain: %s\n", new_lease->options[DHO_DOMAIN_NAME].data));
506
507 RegSetValueExA(RegKey1,
508 "DhcpDomain",
509 0,
510 REG_SZ,
511 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
512 new_lease->options[DHO_DOMAIN_NAME].len);
513
514 RegSetValueExA(RegKey2,
515 "DhcpDomain",
516 0,
517 REG_SZ,
518 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
519 new_lease->options[DHO_DOMAIN_NAME].len);
520 }
521 else
522 {
523 RegDeleteValueW(RegKey1, L"DhcpDomain");
524 RegDeleteValueW(RegKey2, L"DhcpDomain");
525 }
526
527 RegCloseKey(RegKey1);
528 RegCloseKey(RegKey2);
529
530}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define MAX_PATH
Definition: compat.h:34
#define L(x)
Definition: resources.c:13

Referenced by bind_lease().

◆ set_name_servers()

void set_name_servers ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 421 of file dhclient.c.

421 {
422 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
423 HKEY RegKey;
424
425 strcat(Buffer, Adapter->DhclientInfo.name);
427 return;
428
429
430 if( new_lease->options[DHO_DOMAIN_NAME_SERVERS].len ) {
431
432 struct iaddr nameserver;
433 char *nsbuf;
434 int i, addrs =
435 new_lease->options[DHO_DOMAIN_NAME_SERVERS].len / sizeof(ULONG);
436
437 nsbuf = malloc( addrs * sizeof(IP_ADDRESS_STRING) );
438
439 if( nsbuf) {
440 nsbuf[0] = 0;
441 for( i = 0; i < addrs; i++ ) {
442 nameserver.len = sizeof(ULONG);
443 memcpy( nameserver.iabuf,
444 new_lease->options[DHO_DOMAIN_NAME_SERVERS].data +
445 (i * sizeof(ULONG)), sizeof(ULONG) );
446 strcat( nsbuf, piaddr(nameserver) );
447 if( i != addrs-1 ) strcat( nsbuf, "," );
448 }
449
450 DH_DbgPrint(MID_TRACE,("Setting DhcpNameserver: %s\n", nsbuf));
451
452 RegSetValueExA( RegKey, "DhcpNameServer", 0, REG_SZ,
453 (LPBYTE)nsbuf, strlen(nsbuf) + 1 );
454 free( nsbuf );
455 }
456
457 } else {
458 RegDeleteValueW( RegKey, L"DhcpNameServer" );
459 }
460
461 RegCloseKey( RegKey );
462
463}

Referenced by bind_lease().

◆ setup_adapter()

void setup_adapter ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 561 of file dhclient.c.

561 {
562 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
563 struct iaddr netmask;
564 HKEY hkey;
565 int i;
566
567 strcat(Buffer, Adapter->DhclientInfo.name);
569 hkey = NULL;
570
571
572 if( Adapter->NteContext )
573 {
574 DeleteIPAddress( Adapter->NteContext );
575 Adapter->NteContext = 0;
576 }
577
578 /* Set up our default router if we got one from the DHCP server */
579 if( new_lease->options[DHO_SUBNET_MASK].len ) {
581
582 memcpy( netmask.iabuf,
583 new_lease->options[DHO_SUBNET_MASK].data,
584 new_lease->options[DHO_SUBNET_MASK].len );
586 ( *((ULONG*)new_lease->address.iabuf),
587 *((ULONG*)netmask.iabuf),
588 Adapter->IfMib.dwIndex,
589 &Adapter->NteContext,
590 &Adapter->NteInstance );
591 if (hkey) {
592 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)piaddr(new_lease->address), strlen(piaddr(new_lease->address))+1);
593 Buffer[0] = '\0';
594 for(i = 0; i < new_lease->options[DHO_SUBNET_MASK].len; i++)
595 {
596 sprintf(&Buffer[strlen(Buffer)], "%u", new_lease->options[DHO_SUBNET_MASK].data[i]);
597 if (i + 1 < new_lease->options[DHO_SUBNET_MASK].len)
598 strcat(Buffer, ".");
599 }
600 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)Buffer, strlen(Buffer)+1);
601 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)piaddr(new_lease->serveraddress), strlen(piaddr(new_lease->serveraddress))+1);
602
603 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&new_lease->lease, sizeof(DWORD));
604 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&new_lease->obtained, sizeof(DWORD));
605 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_lease->expiry, sizeof(DWORD));
606 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_lease->renewal, sizeof(DWORD));
607 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_lease->rebind, sizeof(DWORD));
608 DWORD dwAddressType = 0;
609 RegSetValueExA(hkey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
610 }
611
612 if( !NT_SUCCESS(Status) )
613 warning("AddIPAddress: %lx\n", Status);
614 }
615
616 if( new_lease->options[DHO_ROUTERS].len ) {
618
619 Adapter->RouterMib.dwForwardDest = 0; /* Default route */
620 Adapter->RouterMib.dwForwardMask = 0;
621 Adapter->RouterMib.dwForwardMetric1 = 1;
622 Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
623
624 if( Adapter->RouterMib.dwForwardNextHop ) {
625 /* If we set a default route before, delete it before continuing */
626 DeleteIpForwardEntry( &Adapter->RouterMib );
627 }
628
629 Adapter->RouterMib.dwForwardNextHop =
630 *((ULONG*)new_lease->options[DHO_ROUTERS].data);
631
633
634 if( !NT_SUCCESS(Status) )
635 warning("CreateIpForwardEntry: %lx\n", Status);
636
637 if (hkey) {
638 Buffer[0] = '\0';
639 for(i = 0; i < new_lease->options[DHO_ROUTERS].len; i++)
640 {
641 sprintf(&Buffer[strlen(Buffer)], "%u", new_lease->options[DHO_ROUTERS].data[i]);
642 if (i + 1 < new_lease->options[DHO_ROUTERS].len)
643 strcat(Buffer, ".");
644 }
645 RegSetValueExA(hkey, "DhcpDefaultGateway", 0, REG_SZ, (LPBYTE)Buffer, strlen(Buffer)+1);
646 }
647 }
648
649 if (hkey)
650 RegCloseKey(hkey);
651}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
Definition: iphlpapi_main.c:67
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
#define sprintf
Definition: sprintf.c:45
ULONG NteInstance
Definition: rosdhcp.h:85
MIB_IFROW IfMib
Definition: rosdhcp.h:81
DWORD dwIndex
Definition: ifmib.h:38
DWORD dwForwardMetric1
Definition: ipmib.h:88
IF_INDEX dwForwardIfIndex
Definition: ipmib.h:75
DWORD dwForwardDest
Definition: ipmib.h:71
DWORD dwForwardMask
Definition: ipmib.h:72
time_t renewal
Definition: dhcpd.h:155
time_t rebind
Definition: dhcpd.h:155

Referenced by bind_lease().

◆ state_bound()

void state_bound ( void ipp)

Definition at line 777 of file dhclient.c.

778{
779 struct interface_info *ip = ipp;
780
782
783 /* T1 has expired. */
784 make_request(ip, ip->client->active);
785 ip->client->xid = ip->client->packet.xid;
786
787 if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) {
788 memcpy(ip->client->destination.iabuf, ip->client->active->
790 ip->client->destination.len = 4;
791 } else
792 ip->client->destination = iaddr_broadcast;
793
794 time(&ip->client->first_sending);
795 ip->client->interval = ip->client->config->initial_interval;
796 ip->client->state = S_RENEWING;
797
798 /* Send the first packet immediately. */
800}
static int state
Definition: maze.c:121
void make_request(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1660
struct iaddr iaddr_broadcast
Definition: dhclient.c:80
#define ASSERT_STATE(state_is, state_shouldbe)
Definition: dhclient.c:88

Referenced by bind_lease().

◆ state_init()

void state_init ( void ipp)

Definition at line 210 of file dhclient.c.

211{
212 struct interface_info *ip = ipp;
213
215
216 /* Make a DHCPDISCOVER packet, and set appropriate per-interface
217 flags. */
218 make_discover(ip, ip->client->active);
219 ip->client->xid = ip->client->packet.xid;
220 ip->client->destination = iaddr_broadcast;
221 ip->client->state = S_SELECTING;
222 time(&ip->client->first_sending);
223 ip->client->interval = ip->client->config->initial_interval;
224
225 /* Add an immediate timeout to cause the first DHCPDISCOVER packet
226 to go out. */
228}
void make_discover(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1577

Referenced by AdapterDiscoveryThread(), device_init(), dhcpnak(), send_request(), state_reboot(), state_selecting(), wined3d_cs_create(), wined3d_cs_exec_reset_state(), and wined3d_device_reset().

◆ state_panic()

void state_panic ( void ipp)

Definition at line 1219 of file dhclient.c.

1220{
1221 CHAR szKeyNameBuffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
1222 CHAR Server[] = "255.255.255.255";
1223 CHAR SubnetMask[] = "255.255.0.0";
1224 CHAR AddressBuffer[32];
1225 struct interface_info *ip = ipp;
1226 uint16_t address_low;
1227 int i;
1228 IPAddr IpAddress;
1229 ULONG Buffer[20];
1231 DWORD ret;
1232 HKEY hKey = NULL;
1233 PDHCP_ADAPTER Adapter = AdapterFindInfo(ip);
1235 DWORD lease = 0;
1236 time_t cur_time, never_time = 0x7FFFFFFF;
1237 struct in_addr addr;
1238 DWORD dwAddressType = 0;
1239
1240 note("No DHCPOFFERS received.");
1241
1242 time(&cur_time);
1243
1244 strcat(szKeyNameBuffer, Adapter->DhclientInfo.name);
1245 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, szKeyNameBuffer, 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
1246 hKey = NULL;
1247
1248 if (Adapter && !Adapter->NteContext)
1249 {
1250 DH_DbgPrint(MID_TRACE,("DHCPCSVC: Failed to receive a response from a DHCP server\n"));
1251 if ((Adapter->AlternateConfiguration != NULL) &&
1252 (Adapter->AlternateConfiguration->IpAddress != 0))
1253 {
1254 /* Use the alternate configuration */
1255 DH_DbgPrint(MID_TRACE,("DHCPCSVC: The alternate configuration will be used.\n"));
1256
1257 /* IPAddress & SubnetMask */
1260 Adapter->IfMib.dwIndex,
1261 &Adapter->NteContext,
1262 &Adapter->NteInstance);
1263 if (!NT_SUCCESS(Status))
1264 DH_DbgPrint(MID_TRACE,("AddIPAddress: %lx\n", Status));
1265
1266 /* DefaultGateway */
1267 if (Adapter->AlternateConfiguration->DefaultGateway != 0)
1268 {
1269 Adapter->RouterMib.dwForwardDest = 0; /* Default route */
1270 Adapter->RouterMib.dwForwardMask = 0;
1271 Adapter->RouterMib.dwForwardMetric1 = 1;
1272 Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
1273
1274 if (Adapter->RouterMib.dwForwardNextHop)
1275 {
1276 /* If we set a default route before, delete it before continuing */
1278 }
1279
1281
1283 if (!NT_SUCCESS(Status))
1284 DH_DbgPrint(MID_TRACE,("CreateIpForwardEntry: %lx\n", Status));
1285 }
1286
1287 if (hKey)
1288 {
1289 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->IpAddress);
1290 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1291 RegSetValueExA(hKey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1292 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->SubnetMask);
1293 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1294 RegSetValueExA(hKey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1295 if (Adapter->AlternateConfiguration->DefaultGateway != 0)
1296 {
1297 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DefaultGateway);
1298 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1299 RegSetValueExA(hKey, "DhcpDefaultGateway", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1300 }
1301 else
1302 {
1303 RegDeleteValueA(hKey, "DhcpDefaultGateway");
1304 }
1305 RegSetValueExA(hKey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server) + 1);
1306 RegDeleteValueA(hKey, "DhcpDomain");
1307
1308 if (Adapter->AlternateConfiguration->DnsServer1 != 0)
1309 {
1310 char *pPtr;
1311 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DnsServer1);
1312 pPtr = RtlIpv4AddressToStringA(&addr, AddressBuffer);
1313 if (Adapter->AlternateConfiguration->DnsServer2 != 0)
1314 {
1315 *pPtr = ' ';
1316 pPtr++;
1317 addr.S_un.S_addr = htonl(Adapter->AlternateConfiguration->DnsServer2);
1319 }
1320
1321 RegSetValueExA(hKey, "DhcpNameServer", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1322 }
1323 else
1324 {
1325 RegDeleteValueA(hKey, "DhcpNameServer");
1326 }
1327
1328 RegDeleteValueA(hKey, "IPAutoconfigurationAddress");
1329 RegDeleteValueA(hKey, "IPAutoconfigurationMask");
1330
1331 RegSetValueExA(hKey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
1332 RegSetValueExA(hKey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1333 RegSetValueExA(hKey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&never_time, sizeof(DWORD));
1334 RegSetValueExA(hKey, "T1", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1335 RegSetValueExA(hKey, "T2", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1336 RegSetValueExA(hKey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
1337 }
1338 }
1339 else
1340 {
1341 /* Generate an automatic private address */
1342 DH_DbgPrint(MID_TRACE,("DHCPCSVC: An automatic private address will be assigned.\n"));
1343
1344 /* FIXME: The address generation code sucks */
1345 srand(0);
1346
1347 for (;;)
1348 {
1349 address_low = rand();
1350 for (i = 0; i < ip->hw_address.hlen; i++)
1351 address_low += ip->hw_address.haddr[i];
1352
1353 IpAddress = htonl(0xA9FE0000 | address_low); // 169.254.X.X
1354
1355 /* Send an ARP request to check if the IP address is already in use */
1356 BufferSize = sizeof(Buffer);
1357 ret = SendARP(IpAddress,
1358 IpAddress,
1359 Buffer,
1360 &BufferSize);
1361 DH_DbgPrint(MID_TRACE,("DHCPCSVC: SendARP returned %lu\n", ret));
1362 if (ret != 0)
1363 {
1364 /* The IP address is not in use */
1365 DH_DbgPrint(MID_TRACE,("DHCPCSVC: Using automatic private address\n"));
1366 Status = AddIPAddress(IpAddress,
1367 htonl(0xFFFF0000), // 255.255.0.0
1368 Adapter->IfMib.dwIndex,
1369 &Adapter->NteContext,
1370 &Adapter->NteInstance);
1371 if (!NT_SUCCESS(Status))
1372 DH_DbgPrint(MID_TRACE,("AddIPAddress: %lx\n", Status));
1373
1374 if (hKey)
1375 {
1376 addr.S_un.S_addr = IpAddress;
1377 RtlIpv4AddressToStringA(&addr, AddressBuffer);
1378 RegSetValueExA(hKey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1379 RegSetValueExA(hKey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask) + 1);
1380 RegSetValueExA(hKey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server) + 1);
1381 RegDeleteValueA(hKey, "DhcpDefaultGateway");
1382 RegDeleteValueA(hKey, "DhcpDomain");
1383 RegDeleteValueA(hKey, "DhcpNameServer");
1384
1385 RegSetValueExA(hKey, "IPAutoconfigurationAddress", 0, REG_SZ, (LPBYTE)AddressBuffer, strlen(AddressBuffer) + 1);
1386 RegSetValueExA(hKey, "IPAutoconfigurationMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask) + 1);
1387
1388 RegSetValueExA(hKey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
1389 RegSetValueExA(hKey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1390 RegSetValueExA(hKey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&never_time, sizeof(DWORD));
1391 RegSetValueExA(hKey, "T1", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1392 RegSetValueExA(hKey, "T2", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
1393 dwAddressType = 1;
1394 RegSetValueExA(hKey, "AddressType", 0, REG_DWORD, (LPBYTE)&dwAddressType, sizeof(DWORD));
1395 }
1396
1397 goto done;
1398 }
1399 }
1400 }
1401 }
1402
1403done:
1404 if (hKey)
1406}
#define BufferSize
Definition: mmc.h:75
unsigned short uint16_t
Definition: stdint.h:35
_ACRTIMP void __cdecl srand(unsigned int)
Definition: misc.c:50
return ret
Definition: mutex.c:146
FxAutoRegKey hKey
GLenum const GLvoid * addr
Definition: glext.h:9621
DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
#define htonl(x)
Definition: module.h:214
ULONG IPAddr
Definition: pfhook.h:35
PALTERNATE_CONFIGURATION AlternateConfiguration
Definition: rosdhcp.h:80
NTSYSAPI PSTR NTAPI RtlIpv4AddressToStringA(_In_ const struct in_addr *Addr, _Out_writes_(16) PSTR S)
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by send_discover().

◆ state_reboot()

void state_reboot ( void ipp)

Definition at line 172 of file dhclient.c.

173{
174 struct interface_info *ip = ipp;
176
177 /* If we don't remember an active lease, go straight to INIT. */
178 if (!ip->client->active || ip->client->active->is_bootp) {
179 state_init(ip);
180 return;
181 }
182
183 /* We are in the rebooting state. */
184 ip->client->state = S_REBOOTING;
185
186 /* make_request doesn't initialize xid because it normally comes
187 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
188 so pick an xid now. */
189 ip->client->xid = RtlRandom(&foo);
190
191 /* Make a DHCPREQUEST packet, and set appropriate per-interface
192 flags. */
193 make_request(ip, ip->client->active);
194 ip->client->destination = iaddr_broadcast;
195 time(&ip->client->first_sending);
196 ip->client->interval = ip->client->config->initial_interval;
197
198 /* Zap the medium list... */
199 ip->client->medium = NULL;
200
201 /* Send out the first DHCPREQUEST packet. */
203}

Referenced by Server_AcquireParameters(), and Server_EnableDhcp().

◆ state_release()

void state_release ( void ipp)

Definition at line 231 of file dhclient.c.

232{
233 struct interface_info *ip = ipp;
235
237
238 /* Make a DHCPRELEASE packet, and set appropriate per-interface
239 flags. */
240 make_release(ip, ip->client->active);
241
242 /* make_request doesn't initialize xid because it normally comes
243 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
244 so pick an xid now. */
245 ip->client->xid = RtlRandom(&foo);
247
248 ip->client->state = S_RELEASED;
250}
void make_release(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1836
void send_release(void *ipp)
Definition: dhclient.c:1552
void unbind_lease(struct interface_info *ip)
Definition: dhclient.c:749
@ S_RELEASED
Definition: dhcpd.h:180

Referenced by Server_ReleaseParameters().

◆ state_selecting()

void state_selecting ( void ipp)

Definition at line 257 of file dhclient.c.

258{
259 struct interface_info *ip = ipp;
260 struct client_lease *lp, *next, *picked;
262
264
265 time(&cur_time);
266
267 /* Cancel state_selecting and send_discover timeouts, since either
268 one could have got us here. */
271
272 /* We have received one or more DHCPOFFER packets. Currently,
273 the only criterion by which we judge leases is whether or
274 not we get a response when we arp for them. */
275 picked = NULL;
276 for (lp = ip->client->offered_leases; lp; lp = next) {
277 next = lp->next;
278
279 /* Check to see if we got an ARPREPLY for the address
280 in this particular lease. */
281 if (!picked) {
282 if( !check_arp(ip,lp) ) goto freeit;
283 picked = lp;
284 picked->next = NULL;
285 } else {
286freeit:
288 }
289 }
290 ip->client->offered_leases = NULL;
291
292 /* If we just tossed all the leases we were offered, go back
293 to square one. */
294 if (!picked) {
295 ip->client->state = S_INIT;
296 state_init(ip);
297 return;
298 }
299
300 /* If it was a BOOTREPLY, we can just take the address right now. */
301 if (!picked->options[DHO_DHCP_MESSAGE_TYPE].len) {
302 ip->client->new = picked;
303
304 /* Make up some lease expiry times
305 XXX these should be configurable. */
306 ip->client->new->expiry = cur_time + 12000;
307 ip->client->new->renewal += cur_time + 8000;
308 ip->client->new->rebind += cur_time + 10000;
309
310 ip->client->state = S_REQUESTING;
311
312 /* Bind to the address we received. */
313 bind_lease(ip);
314 return;
315 }
316
317 /* Go to the REQUESTING state. */
318 ip->client->destination = iaddr_broadcast;
319 ip->client->state = S_REQUESTING;
320 ip->client->first_sending = cur_time;
321 ip->client->interval = ip->client->config->initial_interval;
322
323 /* Make a DHCPREQUEST packet from the lease we picked. */
324 make_request(ip, picked);
325 ip->client->xid = ip->client->packet.xid;
326
327 /* Toss the lease we picked - we'll get it back in a DHCPACK. */
328 free_client_lease(picked);
329
330 /* Add an immediate timeout to send the first DHCPREQUEST packet. */
332}
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by dhcpoffer(), and state_selecting().

◆ stop_client()

void stop_client ( void  )

Definition at line 129 of file dhclient.c.

130{
131 // AdapterStop();
132 // ApiFree();
133 /* FIXME: Close pipe and kill pipe thread */
134}

Referenced by ServiceMain().

◆ unbind_lease()

void unbind_lease ( struct interface_info ip)

Definition at line 749 of file dhclient.c.

750{
751 PDHCP_ADAPTER Adapter;
752
753 if (ip->client->active) {
754 free_client_lease(ip->client->active);
755 ip->client->active = NULL;
756 }
757
758 Adapter = AdapterFindInfo( ip );
759 if (Adapter) {
760 reset_adapter(Adapter);
761 unset_name_servers(Adapter);
762 unset_domain(Adapter);
763 }
764 else {
765 warning("Could not find adapter for info %p\n", ip);
766 return;
767 }
768}
void unset_domain(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:533
void unset_name_servers(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:466
void reset_adapter(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:654

Referenced by state_release().

◆ unset_domain()

void unset_domain ( PDHCP_ADAPTER  Adapter)

Definition at line 533 of file dhclient.c.

535{
536 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
537 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
538 HKEY RegKey1, RegKey2;
539
540 strcat(Buffer1, Adapter->DhclientInfo.name);
541
542 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
543 {
544 return;
545 }
546
547 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
548 {
549 RegCloseKey(RegKey1);
550 return;
551 }
552
553 RegDeleteValueW(RegKey1, L"DhcpDomain");
554 RegDeleteValueW(RegKey2, L"DhcpDomain");
555
556 RegCloseKey(RegKey1);
557 RegCloseKey(RegKey2);
558}

Referenced by unbind_lease().

◆ unset_name_servers()

void unset_name_servers ( PDHCP_ADAPTER  Adapter)

Definition at line 466 of file dhclient.c.

468{
469 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
470 HKEY RegKey;
471
472 strcat(Buffer, Adapter->DhclientInfo.name);
474 return;
475
476 RegDeleteValueW( RegKey, L"DhcpNameServer" );
477
478 RegCloseKey( RegKey );
479}

Referenced by unbind_lease().

◆ usage()

◆ write_client_lease()

void write_client_lease ( struct interface_info ip,
struct client_lease lease,
int  rewrite 
)

Definition at line 1940 of file dhclient.c.

1942{
1943 static int leases_written;
1944 struct tm *t;
1945 int i;
1946
1947 if (!rewrite) {
1948 if (leases_written++ > 20) {
1950 leases_written = 0;
1951 }
1952 }
1953
1954 /* If the lease came from the config file, we don't need to stash
1955 a copy in the lease database. */
1956 if (lease->is_static)
1957 return;
1958
1959 if (!leaseFile) { /* XXX */
1961 if (!leaseFile) {
1962 error("can't create %s", path_dhclient_db);
1963 return;
1964 }
1965 }
1966
1967 fprintf(leaseFile, "lease {\n");
1968 if (lease->is_bootp)
1969 fprintf(leaseFile, " bootp;\n");
1970 fprintf(leaseFile, " interface \"%s\";\n", ip->name);
1971 fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address));
1972 if (lease->filename)
1973 fprintf(leaseFile, " filename \"%s\";\n", lease->filename);
1974 if (lease->server_name)
1975 fprintf(leaseFile, " server-name \"%s\";\n",
1976 lease->server_name);
1977 if (lease->medium)
1978 fprintf(leaseFile, " medium \"%s\";\n", lease->medium->string);
1979 for (i = 0; i < 256; i++)
1980 if (lease->options[i].len)
1981 fprintf(leaseFile, " option %s %s;\n",
1983 pretty_print_option(i, lease->options[i].data,
1984 lease->options[i].len, 1, 1));
1985
1986 t = gmtime(&lease->renewal);
1987 if (t)
1988 fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n",
1989 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1990 t->tm_hour, t->tm_min, t->tm_sec);
1991 t = gmtime(&lease->rebind);
1992 if (t)
1993 fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n",
1994 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1995 t->tm_hour, t->tm_min, t->tm_sec);
1996 t = gmtime(&lease->expiry);
1997 if (t)
1998 fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n",
1999 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
2000 t->tm_hour, t->tm_min, t->tm_sec);
2001 fprintf(leaseFile, "}\n");
2003}
void rewrite_client_leases(struct interface_info *ifi)
Definition: dhclient.c:1918
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
static struct tm * gmtime(const time_t *t)
Definition: time.h:120
GLdouble GLdouble t
Definition: gl.h:2047
unsigned int is_static
Definition: dhcpd.h:165

Referenced by rewrite_client_leases().

Variable Documentation

◆ debug_trace_level

unsigned long debug_trace_level = 0

Definition at line 71 of file dhclient.c.

◆ iaddr_broadcast

struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }

Definition at line 80 of file dhclient.c.

Referenced by state_bound(), state_init(), state_reboot(), and state_selecting().

◆ inaddr_any

struct in_addr inaddr_any

Definition at line 81 of file dhclient.c.

Referenced by init_client(), send_decline(), and send_discover().

◆ leaseFile

FILE* leaseFile

Definition at line 1915 of file dhclient.c.

Referenced by rewrite_client_leases(), and write_client_lease().

◆ log_perror

int log_perror = 1

Definition at line 76 of file dhclient.c.

◆ log_priority

int log_priority

Definition at line 92 of file dhclient.c.

◆ no_daemon

int no_daemon

Definition at line 93 of file dhclient.c.

◆ path_dhclient_conf

char* path_dhclient_conf = _PATH_DHCLIENT_CONF

Definition at line 73 of file dhclient.c.

◆ path_dhclient_db

char* path_dhclient_db = NULL

Definition at line 74 of file dhclient.c.

Referenced by rewrite_client_leases(), and write_client_lease().

◆ privfd

int privfd

Definition at line 77 of file dhclient.c.

◆ routefd

int routefd

Definition at line 95 of file dhclient.c.

◆ scripttime

time_t scripttime

Definition at line 107 of file dhclient.c.

◆ sockaddr_broadcast

struct sockaddr_in sockaddr_broadcast

Definition at line 82 of file dhclient.c.

Referenced by init_client(), send_decline(), and send_discover().

◆ unknown_ok

int unknown_ok = 1

Definition at line 94 of file dhclient.c.

Referenced by check_option().