Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Dnsmasq
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Dnsmasq
Commits
ceae00dd
Commit
ceae00dd
authored
Feb 09, 2012
by
Simon Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lease script should work with IPv6 now.
parent
3634c54e
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
442 additions
and
266 deletions
+442
-266
src/dhcp-common.c
src/dhcp-common.c
+119
-1
src/dhcp.c
src/dhcp.c
+0
-79
src/dhcp6.c
src/dhcp6.c
+1
-1
src/dnsmasq.h
src/dnsmasq.h
+11
-4
src/helper.c
src/helper.c
+135
-39
src/lease.c
src/lease.c
+89
-72
src/option.c
src/option.c
+2
-3
src/rfc2131.c
src/rfc2131.c
+4
-44
src/rfc3315.c
src/rfc3315.c
+81
-23
No files found.
src/dhcp-common.c
View file @
ceae00dd
...
@@ -238,6 +238,124 @@ int match_bytes(struct dhcp_opt *o, unsigned char *p, int len)
...
@@ -238,6 +238,124 @@ int match_bytes(struct dhcp_opt *o, unsigned char *p, int len)
return
0
;
return
0
;
}
}
void
check_dhcp_hosts
(
int
fatal
)
{
/* If the same IP appears in more than one host config, then DISCOVER
for one of the hosts will get the address, but REQUEST will be NAKed,
since the address is reserved by the other one -> protocol loop.
Also check that FQDNs match the domain we are using. */
struct
dhcp_config
*
configs
,
*
cp
;
for
(
configs
=
daemon
->
dhcp_conf
;
configs
;
configs
=
configs
->
next
)
{
char
*
domain
;
if
((
configs
->
flags
&
DHOPT_BANK
)
||
fatal
)
{
for
(
cp
=
configs
->
next
;
cp
;
cp
=
cp
->
next
)
if
((
configs
->
flags
&
cp
->
flags
&
CONFIG_ADDR
)
&&
configs
->
addr
.
s_addr
==
cp
->
addr
.
s_addr
)
{
if
(
fatal
)
die
(
_
(
"duplicate IP address %s in dhcp-config directive."
),
inet_ntoa
(
cp
->
addr
),
EC_BADCONF
);
else
my_syslog
(
MS_DHCP
|
LOG_ERR
,
_
(
"duplicate IP address %s in %s."
),
inet_ntoa
(
cp
->
addr
),
daemon
->
dhcp_hosts_file
);
configs
->
flags
&=
~
CONFIG_ADDR
;
}
/* split off domain part */
if
((
configs
->
flags
&
CONFIG_NAME
)
&&
(
domain
=
strip_hostname
(
configs
->
hostname
)))
configs
->
domain
=
domain
;
}
}
}
void
dhcp_update_configs
(
struct
dhcp_config
*
configs
)
{
/* Some people like to keep all static IP addresses in /etc/hosts.
This goes through /etc/hosts and sets static addresses for any DHCP config
records which don't have an address and whose name matches.
We take care to maintain the invariant that any IP address can appear
in at most one dhcp-host. Since /etc/hosts can be re-read by SIGHUP,
restore the status-quo ante first. */
struct
dhcp_config
*
config
;
struct
crec
*
crec
;
int
prot
=
AF_INET
;
for
(
config
=
configs
;
config
;
config
=
config
->
next
)
if
(
config
->
flags
&
CONFIG_ADDR_HOSTS
)
config
->
flags
&=
~
(
CONFIG_ADDR
|
CONFIG_ADDR6
|
CONFIG_ADDR_HOSTS
);
#ifdef HAVE_DHCP6
again:
#endif
if
(
daemon
->
port
!=
0
)
for
(
config
=
configs
;
config
;
config
=
config
->
next
)
{
int
conflags
=
CONFIG_ADDR
;
int
cacheflags
=
F_IPV4
;
#ifdef HAVE_DHCP6
if
(
prot
==
AF_INET6
)
{
conflags
=
CONFIG_ADDR6
;
cacheflags
=
F_IPV6
;
}
#endif
if
(
!
(
config
->
flags
&
conflags
)
&&
(
config
->
flags
&
CONFIG_NAME
)
&&
(
crec
=
cache_find_by_name
(
NULL
,
config
->
hostname
,
0
,
cacheflags
))
&&
(
crec
->
flags
&
F_HOSTS
))
{
if
(
cache_find_by_name
(
crec
,
config
->
hostname
,
0
,
cacheflags
))
{
/* use primary (first) address */
while
(
crec
&&
!
(
crec
->
flags
&
F_REVERSE
))
crec
=
cache_find_by_name
(
crec
,
config
->
hostname
,
0
,
cacheflags
);
if
(
!
crec
)
continue
;
/* should be never */
inet_ntop
(
prot
,
&
crec
->
addr
.
addr
,
daemon
->
addrbuff
,
ADDRSTRLEN
);
my_syslog
(
MS_DHCP
|
LOG_WARNING
,
_
(
"%s has more than one address in hostsfile, using %s for DHCP"
),
config
->
hostname
,
daemon
->
addrbuff
);
}
if
(
prot
==
AF_INET
&&
!
config_find_by_address
(
configs
,
crec
->
addr
.
addr
.
addr
.
addr4
))
{
config
->
addr
=
crec
->
addr
.
addr
.
addr
.
addr4
;
config
->
flags
|=
CONFIG_ADDR
|
CONFIG_ADDR_HOSTS
;
continue
;
}
#ifdef HAVE_DHCP6
if
(
prot
==
AF_INET6
&&
!
config_find_by_address6
(
configs
,
&
crec
->
addr
.
addr
.
addr
.
addr6
,
129
,
0
))
{
memcpy
(
config
->
hwaddr
,
&
crec
->
addr
.
addr
.
addr
.
addr6
,
IN6ADDRSZ
);
config
->
flags
|=
CONFIG_ADDR6
|
CONFIG_ADDR_HOSTS
;
continue
;
}
#endif
inet_ntop
(
prot
,
&
crec
->
addr
.
addr
,
daemon
->
addrbuff
,
ADDRSTRLEN
);
my_syslog
(
MS_DHCP
|
LOG_WARNING
,
_
(
"duplicate IP address %s (%s) in dhcp-config directive"
),
daemon
->
addrbuff
,
config
->
hostname
);
}
}
#ifdef HAVE_DHCP6
if
(
prot
==
AF_INET
)
{
prot
=
AF_INET6
;
goto
again
;
}
#endif
}
#endif
#endif
src/dhcp.c
View file @
ceae00dd
...
@@ -946,85 +946,6 @@ void dhcp_read_ethers(void)
...
@@ -946,85 +946,6 @@ void dhcp_read_ethers(void)
my_syslog
(
MS_DHCP
|
LOG_INFO
,
_
(
"read %s - %d addresses"
),
ETHERSFILE
,
count
);
my_syslog
(
MS_DHCP
|
LOG_INFO
,
_
(
"read %s - %d addresses"
),
ETHERSFILE
,
count
);
}
}
void
check_dhcp_hosts
(
int
fatal
)
{
/* If the same IP appears in more than one host config, then DISCOVER
for one of the hosts will get the address, but REQUEST will be NAKed,
since the address is reserved by the other one -> protocol loop.
Also check that FQDNs match the domain we are using. */
struct
dhcp_config
*
configs
,
*
cp
;
for
(
configs
=
daemon
->
dhcp_conf
;
configs
;
configs
=
configs
->
next
)
{
char
*
domain
;
if
((
configs
->
flags
&
DHOPT_BANK
)
||
fatal
)
{
for
(
cp
=
configs
->
next
;
cp
;
cp
=
cp
->
next
)
if
((
configs
->
flags
&
cp
->
flags
&
CONFIG_ADDR
)
&&
configs
->
addr
.
s_addr
==
cp
->
addr
.
s_addr
)
{
if
(
fatal
)
die
(
_
(
"duplicate IP address %s in dhcp-config directive."
),
inet_ntoa
(
cp
->
addr
),
EC_BADCONF
);
else
my_syslog
(
MS_DHCP
|
LOG_ERR
,
_
(
"duplicate IP address %s in %s."
),
inet_ntoa
(
cp
->
addr
),
daemon
->
dhcp_hosts_file
);
configs
->
flags
&=
~
CONFIG_ADDR
;
}
/* split off domain part */
if
((
configs
->
flags
&
CONFIG_NAME
)
&&
(
domain
=
strip_hostname
(
configs
->
hostname
)))
configs
->
domain
=
domain
;
}
}
}
void
dhcp_update_configs
(
struct
dhcp_config
*
configs
)
{
/* Some people like to keep all static IP addresses in /etc/hosts.
This goes through /etc/hosts and sets static addresses for any DHCP config
records which don't have an address and whose name matches.
We take care to maintain the invariant that any IP address can appear
in at most one dhcp-host. Since /etc/hosts can be re-read by SIGHUP,
restore the status-quo ante first. */
struct
dhcp_config
*
config
;
struct
crec
*
crec
;
for
(
config
=
configs
;
config
;
config
=
config
->
next
)
if
(
config
->
flags
&
CONFIG_ADDR_HOSTS
)
config
->
flags
&=
~
(
CONFIG_ADDR
|
CONFIG_ADDR_HOSTS
);
if
(
daemon
->
port
!=
0
)
for
(
config
=
configs
;
config
;
config
=
config
->
next
)
if
(
!
(
config
->
flags
&
CONFIG_ADDR
)
&&
(
config
->
flags
&
CONFIG_NAME
)
&&
(
crec
=
cache_find_by_name
(
NULL
,
config
->
hostname
,
0
,
F_IPV4
))
&&
(
crec
->
flags
&
F_HOSTS
))
{
if
(
cache_find_by_name
(
crec
,
config
->
hostname
,
0
,
F_IPV4
))
{
/* use primary (first) address */
while
(
crec
&&
!
(
crec
->
flags
&
F_REVERSE
))
crec
=
cache_find_by_name
(
crec
,
config
->
hostname
,
0
,
F_IPV4
);
if
(
!
crec
)
continue
;
/* should be never */
my_syslog
(
MS_DHCP
|
LOG_WARNING
,
_
(
"%s has more than one address in hostsfile, using %s for DHCP"
),
config
->
hostname
,
inet_ntoa
(
crec
->
addr
.
addr
.
addr
.
addr4
));
}
if
(
config_find_by_address
(
configs
,
crec
->
addr
.
addr
.
addr
.
addr4
))
my_syslog
(
MS_DHCP
|
LOG_WARNING
,
_
(
"duplicate IP address %s (%s) in dhcp-config directive"
),
inet_ntoa
(
crec
->
addr
.
addr
.
addr
.
addr4
),
config
->
hostname
);
else
{
config
->
addr
=
crec
->
addr
.
addr
.
addr
.
addr4
;
config
->
flags
|=
CONFIG_ADDR
|
CONFIG_ADDR_HOSTS
;
}
}
}
/* If we've not found a hostname any other way, try and see if there's one in /etc/hosts
/* If we've not found a hostname any other way, try and see if there's one in /etc/hosts
for this address. If it has a domain part, that must match the set domain and
for this address. If it has a domain part, that must match the set domain and
...
...
src/dhcp6.c
View file @
ceae00dd
...
@@ -214,7 +214,7 @@ void dhcp6_packet(time_t now)
...
@@ -214,7 +214,7 @@ void dhcp6_packet(time_t now)
lease_prune
(
NULL
,
now
);
/* lose any expired leases */
lease_prune
(
NULL
,
now
);
/* lose any expired leases */
msg
.
msg_iov
=
&
daemon
->
dhcp_packet
;
msg
.
msg_iov
=
&
daemon
->
dhcp_packet
;
sz
=
dhcp6_reply
(
parm
.
current
,
ifr
.
ifr_name
,
sz
,
IN6_IS_ADDR_MULTICAST
(
&
from
),
now
);
sz
=
dhcp6_reply
(
parm
.
current
,
if
_index
,
if
r
.
ifr_name
,
sz
,
IN6_IS_ADDR_MULTICAST
(
&
from
),
now
);
/* ifr.ifr_name, if_index, (size_t)sz,
/* ifr.ifr_name, if_index, (size_t)sz,
now, unicast_dest, &is_inform, pxe_fd, iface_addr); */
now, unicast_dest, &is_inform, pxe_fd, iface_addr); */
lease_update_file
(
now
);
lease_update_file
(
now
);
...
...
src/dnsmasq.h
View file @
ceae00dd
...
@@ -911,12 +911,9 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
...
@@ -911,12 +911,9 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
unsigned
char
*
clid
,
int
clid_len
,
unsigned
char
*
clid
,
int
clid_len
,
unsigned
char
*
hwaddr
,
int
hw_len
,
unsigned
char
*
hwaddr
,
int
hw_len
,
int
hw_type
,
char
*
hostname
);
int
hw_type
,
char
*
hostname
);
void
dhcp_update_configs
(
struct
dhcp_config
*
configs
);
void
dhcp_read_ethers
(
void
);
void
dhcp_read_ethers
(
void
);
void
check_dhcp_hosts
(
int
fatal
);
struct
dhcp_config
*
config_find_by_address
(
struct
dhcp_config
*
configs
,
struct
in_addr
addr
);
struct
dhcp_config
*
config_find_by_address
(
struct
dhcp_config
*
configs
,
struct
in_addr
addr
);
char
*
host_from_dns
(
struct
in_addr
addr
);
char
*
host_from_dns
(
struct
in_addr
addr
);
char
*
get_domain
(
struct
in_addr
addr
);
#endif
#endif
/* lease.c */
/* lease.c */
...
@@ -944,6 +941,10 @@ void lease_prune(struct dhcp_lease *target, time_t now);
...
@@ -944,6 +941,10 @@ void lease_prune(struct dhcp_lease *target, time_t now);
void
lease_update_from_configs
(
void
);
void
lease_update_from_configs
(
void
);
int
do_script_run
(
time_t
now
);
int
do_script_run
(
time_t
now
);
void
rerun_scripts
(
void
);
void
rerun_scripts
(
void
);
#ifdef HAVE_SCRIPT
void
lease_add_extradata
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
data
,
unsigned
int
len
,
int
delim
);
#endif
#endif
#endif
/* rfc2131.c */
/* rfc2131.c */
...
@@ -1026,15 +1027,18 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
...
@@ -1026,15 +1027,18 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
struct
dhcp_context
*
context
,
struct
dhcp_context
*
context
,
unsigned
char
*
duid
,
int
duid_len
,
unsigned
char
*
duid
,
int
duid_len
,
char
*
hostname
);
char
*
hostname
);
struct
dhcp_config
*
config_find_by_address6
(
struct
dhcp_config
*
configs
,
struct
in6_addr
*
net
,
int
prefix
,
u64
addr
);
void
make_duid
(
time_t
now
);
void
make_duid
(
time_t
now
);
#endif
#endif
/* rfc3315.c */
/* rfc3315.c */
#ifdef HAVE_DHCP6
#ifdef HAVE_DHCP6
size_t
dhcp6_reply
(
struct
dhcp_context
*
context
,
char
*
iface_name
,
size_t
sz
,
int
is_multicast
,
time_t
now
);
size_t
dhcp6_reply
(
struct
dhcp_context
*
context
,
int
interface
,
char
*
iface_name
,
size_t
sz
,
int
is_multicast
,
time_t
now
);
#endif
#endif
/* dhcp-common.c */
/* dhcp-common.c */
#ifdef HAVE_DHCP
void
dhcp_common_init
(
void
);
void
dhcp_common_init
(
void
);
ssize_t
recv_dhcp_packet
(
int
fd
,
struct
msghdr
*
msg
);
ssize_t
recv_dhcp_packet
(
int
fd
,
struct
msghdr
*
msg
);
struct
dhcp_netid
*
run_tag_if
(
struct
dhcp_netid
*
input
);
struct
dhcp_netid
*
run_tag_if
(
struct
dhcp_netid
*
input
);
...
@@ -1044,3 +1048,6 @@ int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
...
@@ -1044,3 +1048,6 @@ int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
char
*
strip_hostname
(
char
*
hostname
);
char
*
strip_hostname
(
char
*
hostname
);
void
log_tags
(
struct
dhcp_netid
*
netid
,
u32
xid
);
void
log_tags
(
struct
dhcp_netid
*
netid
,
u32
xid
);
int
match_bytes
(
struct
dhcp_opt
*
o
,
unsigned
char
*
p
,
int
len
);
int
match_bytes
(
struct
dhcp_opt
*
o
,
unsigned
char
*
p
,
int
len
);
void
dhcp_update_configs
(
struct
dhcp_config
*
configs
);
void
check_dhcp_hosts
(
int
fatal
);
#endif
src/helper.c
View file @
ceae00dd
...
@@ -46,8 +46,9 @@ static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end,
...
@@ -46,8 +46,9 @@ static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end,
struct
script_data
struct
script_data
{
{
unsigned
char
action
,
hwaddr_len
,
hwaddr_type
;
int
flags
;
unsigned
char
clid_len
,
hostname_len
,
ed_len
;
int
action
,
hwaddr_len
,
hwaddr_type
;
int
clid_len
,
hostname_len
,
ed_len
;
struct
in_addr
addr
,
giaddr
;
struct
in_addr
addr
,
giaddr
;
unsigned
int
remaining_time
;
unsigned
int
remaining_time
;
#ifdef HAVE_BROKEN_RTC
#ifdef HAVE_BROKEN_RTC
...
@@ -57,6 +58,7 @@ struct script_data
...
@@ -57,6 +58,7 @@ struct script_data
#endif
#endif
unsigned
char
hwaddr
[
DHCP_CHADDR_MAX
];
unsigned
char
hwaddr
[
DHCP_CHADDR_MAX
];
char
interface
[
IF_NAMESIZE
];
char
interface
[
IF_NAMESIZE
];
};
};
static
struct
script_data
*
buf
=
NULL
;
static
struct
script_data
*
buf
=
NULL
;
...
@@ -173,7 +175,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -173,7 +175,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
char
*
p
,
*
action_str
,
*
hostname
=
NULL
,
*
domain
=
NULL
;
char
*
p
,
*
action_str
,
*
hostname
=
NULL
,
*
domain
=
NULL
;
unsigned
char
*
buf
=
(
unsigned
char
*
)
daemon
->
namebuff
;
unsigned
char
*
buf
=
(
unsigned
char
*
)
daemon
->
namebuff
;
unsigned
char
*
end
,
*
extradata
,
*
alloc_buff
=
NULL
;
unsigned
char
*
end
,
*
extradata
,
*
alloc_buff
=
NULL
;
int
err
=
0
;
int
is6
,
err
=
0
;
free
(
alloc_buff
);
free
(
alloc_buff
);
...
@@ -199,17 +201,34 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -199,17 +201,34 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
action_str
=
"old"
;
action_str
=
"old"
;
else
else
continue
;
continue
;
is6
=
!!
(
data
.
flags
&
(
LEASE_TA
|
LEASE_NA
));
/* stringify MAC into dhcp_buff */
if
(
!
is6
)
p
=
daemon
->
dhcp_buff
;
{
if
(
data
.
hwaddr_type
!=
ARPHRD_ETHER
||
data
.
hwaddr_len
==
0
)
/* stringify MAC into dhcp_buff */
p
+=
sprintf
(
p
,
"%.2x-"
,
data
.
hwaddr_type
);
p
=
daemon
->
dhcp_buff
;
for
(
i
=
0
;
(
i
<
data
.
hwaddr_len
)
&&
(
i
<
DHCP_CHADDR_MAX
);
i
++
)
if
(
data
.
hwaddr_type
!=
ARPHRD_ETHER
||
data
.
hwaddr_len
==
0
)
{
p
+=
sprintf
(
p
,
"%.2x-"
,
data
.
hwaddr_type
);
p
+=
sprintf
(
p
,
"%.2x"
,
data
.
hwaddr
[
i
]);
for
(
i
=
0
;
(
i
<
data
.
hwaddr_len
)
&&
(
i
<
DHCP_CHADDR_MAX
);
i
++
)
if
(
i
!=
data
.
hwaddr_len
-
1
)
{
p
+=
sprintf
(
p
,
":"
);
p
+=
sprintf
(
p
,
"%.2x"
,
data
.
hwaddr
[
i
]);
}
if
(
i
!=
data
.
hwaddr_len
-
1
)
p
+=
sprintf
(
p
,
":"
);
}
}
#ifdef HAVE_DHCP6
else
{
/* duid not MAC for IPv6 */
for
(
p
=
daemon
->
dhcp_buff
,
i
=
0
;
i
<
data
.
clid_len
;
i
++
)
{
p
+=
sprintf
(
p
,
"%.2x"
,
buf
[
i
]);
if
(
i
!=
data
.
clid_len
-
1
)
p
+=
sprintf
(
p
,
":"
);
}
}
#endif
/* expiry or length into dhcp_buff2 */
/* expiry or length into dhcp_buff2 */
#ifdef HAVE_BROKEN_RTC
#ifdef HAVE_BROKEN_RTC
...
@@ -228,12 +247,26 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -228,12 +247,26 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
continue
;
continue
;
/* CLID into packet */
/* CLID into packet */
for
(
p
=
daemon
->
packet
,
i
=
0
;
i
<
data
.
clid_len
;
i
++
)
if
(
!
is6
)
for
(
p
=
daemon
->
packet
,
i
=
0
;
i
<
data
.
clid_len
;
i
++
)
{
p
+=
sprintf
(
p
,
"%.2x"
,
buf
[
i
]);
if
(
i
!=
data
.
clid_len
-
1
)
p
+=
sprintf
(
p
,
":"
);
}
#ifdef HAVE_DHCP6
else
{
{
p
+=
sprintf
(
p
,
"%.2x"
,
buf
[
i
]);
/* or IAID and server DUID for IPv6 */
if
(
i
!=
data
.
clid_len
-
1
)
sprintf
(
daemon
->
dhcp_buff3
,
"%s%u"
,
data
.
flags
&
LEASE_TA
?
"T"
:
""
,
data
.
hwaddr_type
);
p
+=
sprintf
(
p
,
":"
);
for
(
p
=
daemon
->
packet
,
i
=
0
;
i
<
daemon
->
duid_len
;
i
++
)
{
p
+=
sprintf
(
p
,
"%.2x"
,
daemon
->
duid
[
i
]);
if
(
i
!=
daemon
->
duid_len
-
1
)
p
+=
sprintf
(
p
,
":"
);
}
}
}
#endif
buf
+=
data
.
clid_len
;
buf
+=
data
.
clid_len
;
...
@@ -253,14 +286,29 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -253,14 +286,29 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
extradata
=
buf
+
data
.
hostname_len
;
extradata
=
buf
+
data
.
hostname_len
;
if
(
!
is6
)
inet_ntop
(
AF_INET
,
&
data
.
addr
,
daemon
->
addrbuff
,
ADDRSTRLEN
);
#ifdef HAVE_DHCP6
else
inet_ntop
(
AF_INET6
,
&
data
.
hwaddr
,
daemon
->
addrbuff
,
ADDRSTRLEN
);
#endif
#ifdef HAVE_LUASCRIPT
#ifdef HAVE_LUASCRIPT
if
(
daemon
->
luascript
)
if
(
daemon
->
luascript
)
{
{
lua_getglobal
(
lua
,
"lease"
);
/* function to call */
lua_getglobal
(
lua
,
"lease"
);
/* function to call */
lua_pushstring
(
lua
,
action_str
);
/* arg1 - action */
lua_pushstring
(
lua
,
action_str
);
/* arg1 - action */
lua_newtable
(
lua
);
/* arg2 - data table */
lua_newtable
(
lua
);
/* arg2 - data table */
if
(
data
.
clid_len
!=
0
)
if
(
is6
)
{
lua_pushstring
(
lua
,
daemon
->
packet
);
lua_setfield
(
lua
,
-
2
,
"duid"
);
lua_pushstring
(
lua
,
daemon
->
dhcp_buff3
);
lua_setfield
(
lua
,
-
2
,
"iaid"
);
}
if
(
!
is6
&&
data
.
clid_len
!=
0
)
{
{
lua_pushstring
(
lua
,
daemon
->
packet
);
lua_pushstring
(
lua
,
daemon
->
packet
);
lua_setfield
(
lua
,
-
2
,
"client_id"
);
lua_setfield
(
lua
,
-
2
,
"client_id"
);
...
@@ -294,20 +342,36 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -294,20 +342,36 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
end
=
extradata
+
data
.
ed_len
;
end
=
extradata
+
data
.
ed_len
;
buf
=
extradata
;
buf
=
extradata
;
buf
=
grab_extradata_lua
(
buf
,
end
,
"vendor_class"
);
if
(
!
is6
)
buf
=
grab_extradata_lua
(
buf
,
end
,
"vendor_class"
);
#ifdef HAVE_DHCP6
else
for
(
i
=
0
;
i
<
data
.
hwaddr_len
;
i
++
)
{
sprintf
(
daemon
->
dhcp_buff2
,
"vendor_class%i"
,
i
);
buf
=
grab_extradata_lua
(
buf
,
end
,
daemon
->
dhcp_buff2
);
}
#endif
buf
=
grab_extradata_lua
(
buf
,
end
,
"supplied_hostname"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"supplied_hostname"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_oui"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_serial"
);
if
(
!
is6
)
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_class"
);
{
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_oui"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_serial"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"cpewan_class"
);
}
buf
=
grab_extradata_lua
(
buf
,
end
,
"tags"
);
buf
=
grab_extradata_lua
(
buf
,
end
,
"tags"
);
for
(
i
=
0
;
buf
;
i
++
)
for
(
i
=
0
;
buf
;
i
++
)
{
{
sprintf
(
daemon
->
dhcp_buff2
,
"user_class%i"
,
i
);
sprintf
(
daemon
->
dhcp_buff2
,
"user_class%i"
,
i
);
buf
=
grab_extradata_lua
(
buf
,
end
,
daemon
->
dhcp_buff2
);
buf
=
grab_extradata_lua
(
buf
,
end
,
daemon
->
dhcp_buff2
);
}
}
if
(
data
.
giaddr
.
s_addr
!=
0
)
if
(
!
is6
&&
data
.
giaddr
.
s_addr
!=
0
)
{
{
lua_pushstring
(
lua
,
inet_ntoa
(
data
.
giaddr
));
lua_pushstring
(
lua
,
inet_ntoa
(
data
.
giaddr
));
lua_setfield
(
lua
,
-
2
,
"relay_address"
);
lua_setfield
(
lua
,
-
2
,
"relay_address"
);
...
@@ -325,10 +389,13 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -325,10 +389,13 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
lua_setfield
(
lua
,
-
2
,
"old_hostname"
);
lua_setfield
(
lua
,
-
2
,
"old_hostname"
);
}
}
lua_pushstring
(
lua
,
daemon
->
dhcp_buff
);
if
(
!
is6
)
lua_setfield
(
lua
,
-
2
,
"mac_address"
);
{
lua_pushstring
(
lua
,
daemon
->
dhcp_buff
);
lua_pushstring
(
lua
,
inet_ntoa
(
data
.
addr
));
lua_setfield
(
lua
,
-
2
,
"mac_address"
);
}
lua_pushstring
(
lua
,
daemon
->
addrbuff
);
lua_setfield
(
lua
,
-
2
,
"ip_address"
);
lua_setfield
(
lua
,
-
2
,
"ip_address"
);
lua_call
(
lua
,
2
,
0
);
/* pass 2 values, expect 0 */
lua_call
(
lua
,
2
,
0
);
/* pass 2 values, expect 0 */
...
@@ -372,7 +439,13 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -372,7 +439,13 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
continue
;
continue
;
}
}
if
(
data
.
clid_len
!=
0
)
if
(
is6
)
{
my_setenv
(
"DNSMASQ_IAID"
,
daemon
->
dhcp_buff3
,
&
err
);
my_setenv
(
"DNSMASQ_DUID"
,
daemon
->
packet
,
&
err
);
}
if
(
!
is6
&&
data
.
clid_len
!=
0
)
my_setenv
(
"DNSMASQ_CLIENT_ID"
,
daemon
->
packet
,
&
err
);
my_setenv
(
"DNSMASQ_CLIENT_ID"
,
daemon
->
packet
,
&
err
);
if
(
strlen
(
data
.
interface
)
!=
0
)
if
(
strlen
(
data
.
interface
)
!=
0
)
...
@@ -389,11 +462,27 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -389,11 +462,27 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
end
=
extradata
+
data
.
ed_len
;
end
=
extradata
+
data
.
ed_len
;
buf
=
extradata
;
buf
=
extradata
;
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_VENDOR_CLASS"
,
&
err
);
if
(
!
is6
)
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_VENDOR_CLASS"
,
&
err
);
#ifdef HAVE_DHCP6
else
for
(
i
=
0
;
i
<
data
.
hwaddr_len
;
i
++
)
{
sprintf
(
daemon
->
dhcp_buff2
,
"DNSMASQ_VENDOR_CLASS%i"
,
i
);
buf
=
grab_extradata
(
buf
,
end
,
daemon
->
dhcp_buff2
,
&
err
);
}
#endif
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_SUPPLIED_HOSTNAME"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_SUPPLIED_HOSTNAME"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_OUI"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_SERIAL"
,
&
err
);
if
(
!
is6
)
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_CLASS"
,
&
err
);
{
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_OUI"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_SERIAL"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_CPEWAN_CLASS"
,
&
err
);
}
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_TAGS"
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
"DNSMASQ_TAGS"
,
&
err
);
for
(
i
=
0
;
buf
;
i
++
)
for
(
i
=
0
;
buf
;
i
++
)
...
@@ -402,7 +491,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -402,7 +491,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
buf
=
grab_extradata
(
buf
,
end
,
daemon
->
dhcp_buff2
,
&
err
);
buf
=
grab_extradata
(
buf
,
end
,
daemon
->
dhcp_buff2
,
&
err
);
}
}
if
(
data
.
giaddr
.
s_addr
!=
0
)
if
(
!
is6
&&
data
.
giaddr
.
s_addr
!=
0
)
my_setenv
(
"DNSMASQ_RELAY_ADDRESS"
,
inet_ntoa
(
data
.
giaddr
),
&
err
);
my_setenv
(
"DNSMASQ_RELAY_ADDRESS"
,
inet_ntoa
(
data
.
giaddr
),
&
err
);
if
(
data
.
action
!=
ACTION_DEL
&&
data
.
remaining_time
!=
0
)
if
(
data
.
action
!=
ACTION_DEL
&&
data
.
remaining_time
!=
0
)
...
@@ -427,7 +516,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
...
@@ -427,7 +516,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
{
{
execl
(
daemon
->
lease_change_command
,
execl
(
daemon
->
lease_change_command
,
p
?
p
+
1
:
daemon
->
lease_change_command
,
p
?
p
+
1
:
daemon
->
lease_change_command
,
action_str
,
daemon
->
dhcp_buff
,
inet_ntoa
(
data
.
addr
)
,
hostname
,
(
char
*
)
NULL
);
action_str
,
daemon
->
dhcp_buff
,
daemon
->
addrbuff
,
hostname
,
(
char
*
)
NULL
);
err
=
errno
;
err
=
errno
;
}
}
/* failed, send event so the main process logs the problem */
/* failed, send event so the main process logs the problem */
...
@@ -493,7 +582,13 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
...
@@ -493,7 +582,13 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
unsigned
char
*
p
;
unsigned
char
*
p
;
size_t
size
;
size_t
size
;
unsigned
int
hostname_len
=
0
,
clid_len
=
0
,
ed_len
=
0
;
unsigned
int
hostname_len
=
0
,
clid_len
=
0
,
ed_len
=
0
;
int
fd
=
daemon
->
dhcpfd
;
#ifdef HAVE_DHCP6
if
(
!
daemon
->
dhcp
)
fd
=
daemon
->
dhcp6fd
;
#endif
/* no script */
/* no script */
if
(
daemon
->
helperfd
==
-
1
)
if
(
daemon
->
helperfd
==
-
1
)
return
;
return
;
...
@@ -524,6 +619,7 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
...
@@ -524,6 +619,7 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
}
}
buf
->
action
=
action
;
buf
->
action
=
action
;
buf
->
flags
=
lease
->
flags
;
buf
->
hwaddr_len
=
lease
->
hwaddr_len
;
buf
->
hwaddr_len
=
lease
->
hwaddr_len
;
buf
->
hwaddr_type
=
lease
->
hwaddr_type
;
buf
->
hwaddr_type
=
lease
->
hwaddr_type
;
buf
->
clid_len
=
clid_len
;
buf
->
clid_len
=
clid_len
;
...
@@ -531,8 +627,8 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
...
@@ -531,8 +627,8 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
buf
->
hostname_len
=
hostname_len
;
buf
->
hostname_len
=
hostname_len
;
buf
->
addr
=
lease
->
addr
;
buf
->
addr
=
lease
->
addr
;
buf
->
giaddr
=
lease
->
giaddr
;
buf
->
giaddr
=
lease
->
giaddr
;
memcpy
(
buf
->
hwaddr
,
lease
->
hwaddr
,
lease
->
hwaddr_len
);
memcpy
(
buf
->
hwaddr
,
lease
->
hwaddr
,
DHCP_CHADDR_MAX
);
if
(
!
indextoname
(
daemon
->
dhcp
fd
,
lease
->
last_interface
,
buf
->
interface
))
if
(
!
indextoname
(
fd
,
lease
->
last_interface
,
buf
->
interface
))
buf
->
interface
[
0
]
=
0
;
buf
->
interface
[
0
]
=
0
;
#ifdef HAVE_BROKEN_RTC
#ifdef HAVE_BROKEN_RTC
...
...
src/lease.c
View file @
ceae00dd
...
@@ -28,13 +28,9 @@ void lease_init(time_t now)
...
@@ -28,13 +28,9 @@ void lease_init(time_t now)
struct
dhcp_lease
*
lease
;
struct
dhcp_lease
*
lease
;
int
clid_len
,
hw_len
,
hw_type
;
int
clid_len
,
hw_len
,
hw_type
;
FILE
*
leasestream
;
FILE
*
leasestream
;
#ifdef HAVE_DHCP6
int
v6pass
=
0
;
int
lease_type
=
0
;
#endif
leases_left
=
daemon
->
dhcp_max
;
leases_left
=
daemon
->
dhcp_max
;
if
(
option_bool
(
OPT_LEASE_RO
))
if
(
option_bool
(
OPT_LEASE_RO
))
{
{
/* run "<lease_change_script> init" once to get the
/* run "<lease_change_script> init" once to get the
...
@@ -68,58 +64,68 @@ void lease_init(time_t now)
...
@@ -68,58 +64,68 @@ void lease_init(time_t now)
rewind
(
leasestream
);
rewind
(
leasestream
);
}
}
#ifdef HAVE_DHCP6
again:
#endif
/* client-id max length is 255 which is 255*2 digits + 254 colons
/* client-id max length is 255 which is 255*2 digits + 254 colons
borrow DNS packet buffer which is always larger than 1000 bytes */
borrow DNS packet buffer which is always larger than 1000 bytes */
if
(
leasestream
)
if
(
leasestream
)
while
(
fscanf
(
leasestream
,
"%lu %255s %64s %255s %764s"
,
while
(
fscanf
(
leasestream
,
"%255s %255s"
,
daemon
->
dhcp_buff3
,
daemon
->
dhcp_buff2
)
==
2
)
&
ei
,
daemon
->
dhcp_buff2
,
daemon
->
namebuff
,
daemon
->
dhcp_buff
,
daemon
->
packet
)
==
5
)
{
{
if
(
strcmp
(
daemon
->
dhcp_buff3
,
"duid"
)
==
0
)
{
daemon
->
duid_len
=
parse_hex
(
daemon
->
dhcp_buff2
,
(
unsigned
char
*
)
daemon
->
dhcp_buff2
,
130
,
NULL
,
NULL
);
daemon
->
duid
=
safe_malloc
(
daemon
->
duid_len
);
memcpy
(
daemon
->
duid
,
daemon
->
dhcp_buff2
,
daemon
->
duid_len
);
continue
;
}
ei
=
atol
(
daemon
->
dhcp_buff3
);
if
(
fscanf
(
leasestream
,
" %64s %255s %764s"
,
daemon
->
namebuff
,
daemon
->
dhcp_buff
,
daemon
->
packet
)
!=
3
)
break
;
clid_len
=
0
;
if
(
strcmp
(
daemon
->
packet
,
"*"
)
!=
0
)
clid_len
=
parse_hex
(
daemon
->
packet
,
(
unsigned
char
*
)
daemon
->
packet
,
255
,
NULL
,
NULL
);
if
(
inet_pton
(
AF_INET
,
daemon
->
namebuff
,
&
addr
.
addr
.
addr4
)
&&
(
lease
=
lease4_allocate
(
addr
.
addr
.
addr4
)))
{
hw_len
=
parse_hex
(
daemon
->
dhcp_buff2
,
(
unsigned
char
*
)
daemon
->
dhcp_buff2
,
DHCP_CHADDR_MAX
,
NULL
,
&
hw_type
);
/* For backwards compatibility, no explict MAC address type means ether. */
if
(
hw_type
==
0
&&
hw_len
!=
0
)
hw_type
=
ARPHRD_ETHER
;
lease_set_hwaddr
(
lease
,
(
unsigned
char
*
)
daemon
->
dhcp_buff2
,
(
unsigned
char
*
)
daemon
->
packet
,
hw_len
,
hw_type
,
clid_len
);
if
(
strcmp
(
daemon
->
dhcp_buff
,
"*"
)
!=
0
)
lease_set_hostname
(
lease
,
daemon
->
dhcp_buff
,
0
,
get_domain
(
lease
->
addr
),
NULL
);
}
#ifdef HAVE_DHCP6
#ifdef HAVE_DHCP6
if
(
v6pass
)
else
if
(
inet_pton
(
AF_INET6
,
daemon
->
namebuff
,
&
addr
.
addr
.
addr6
)
)
{
{
char
*
s
=
daemon
->
dhcp_buff2
;
char
*
s
=
daemon
->
dhcp_buff2
;
int
lease_type
=
LEASE_NA
;
if
(
s
[
0
]
==
'T'
)
if
(
s
[
0
]
==
'T'
)
{
{
lease_type
=
LEASE_TA
;
lease_type
=
LEASE_TA
;
s
++
;
s
++
;
}
}
else
lease_type
=
LEASE_NA
;
hw_type
=
atoi
(
s
);
hw_type
=
atoi
(
s
);
if
((
lease
=
lease6_allocate
(
&
addr
.
addr
.
addr6
,
lease_type
)))
{
lease_set_hwaddr
(
lease
,
NULL
,
(
unsigned
char
*
)
daemon
->
packet
,
0
,
hw_type
,
clid_len
);
if
(
strcmp
(
daemon
->
dhcp_buff
,
"*"
)
!=
0
)
lease_set_hostname
(
lease
,
daemon
->
dhcp_buff
,
0
,
get_domain6
((
struct
in6_addr
*
)
lease
->
hwaddr
),
NULL
);
}
}
}
else
#endif
#endif
{
hw_len
=
parse_hex
(
daemon
->
dhcp_buff2
,
(
unsigned
char
*
)
daemon
->
dhcp_buff2
,
DHCP_CHADDR_MAX
,
NULL
,
&
hw_type
);
/* For backwards compatibility, no explict MAC address type means ether. */
if
(
hw_type
==
0
&&
hw_len
!=
0
)
hw_type
=
ARPHRD_ETHER
;
}
#ifdef HAVE_DHCP6
if
(
v6pass
)
inet_pton
(
AF_INET6
,
daemon
->
namebuff
,
&
addr
.
addr
.
addr6
);
else
else
#endif
break
;
inet_pton
(
AF_INET
,
daemon
->
namebuff
,
&
addr
.
addr
.
addr4
);
clid_len
=
0
;
if
(
strcmp
(
daemon
->
packet
,
"*"
)
!=
0
)
clid_len
=
parse_hex
(
daemon
->
packet
,
(
unsigned
char
*
)
daemon
->
packet
,
255
,
NULL
,
NULL
);
#ifdef HAVE_DHCP6
if
(
v6pass
)
lease
=
lease6_allocate
(
&
addr
.
addr
.
addr6
,
lease_type
);
else
#endif
lease
=
lease4_allocate
(
addr
.
addr
.
addr4
);
if
(
!
lease
)
if
(
!
lease
)
die
(
_
(
"too many stored leases"
),
NULL
,
EC_MISC
);
die
(
_
(
"too many stored leases"
),
NULL
,
EC_MISC
);
...
@@ -134,44 +140,17 @@ void lease_init(time_t now)
...
@@ -134,44 +140,17 @@ void lease_init(time_t now)
even when sizeof(time_t) == 8 */
even when sizeof(time_t) == 8 */
lease
->
expires
=
(
time_t
)
ei
;
lease
->
expires
=
(
time_t
)
ei
;
#endif
#endif
#ifdef HAVE_DHCP6
if
(
v6pass
)
lease_set_hwaddr
(
lease
,
NULL
,
(
unsigned
char
*
)
daemon
->
packet
,
0
,
hw_type
,
clid_len
);
else
#endif
lease_set_hwaddr
(
lease
,
(
unsigned
char
*
)
daemon
->
dhcp_buff2
,
(
unsigned
char
*
)
daemon
->
packet
,
hw_len
,
hw_type
,
clid_len
);
if
(
strcmp
(
daemon
->
dhcp_buff
,
"*"
)
!=
0
)
{
#ifdef HAVE_DHCP6
if
(
v6pass
)
lease_set_hostname
(
lease
,
daemon
->
dhcp_buff
,
0
,
get_domain6
((
struct
in6_addr
*
)
lease
->
hwaddr
),
NULL
);
else
#endif
lease_set_hostname
(
lease
,
daemon
->
dhcp_buff
,
0
,
get_domain
(
lease
->
addr
),
NULL
);
}
/* set these correctly: the "old" events are generated later from
/* set these correctly: the "old" events are generated later from
the startup synthesised SIGHUP. */
the startup synthesised SIGHUP. */
lease
->
flags
|
=
~
(
LEASE_NEW
|
LEASE_CHANGED
);
lease
->
flags
&
=
~
(
LEASE_NEW
|
LEASE_CHANGED
);
}
}
#ifdef HAVE_DHCP6
#ifdef HAVE_DHCP6
if
(
!
v6pass
)
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
{
if
(
!
daemon
->
duid
&&
daemon
->
dhcp6
)
if
(
fscanf
(
leasestream
,
"duid %255s"
,
daemon
->
dhcp_buff
)
==
1
)
make_duid
(
now
);
{
daemon
->
duid_len
=
parse_hex
(
daemon
->
dhcp_buff
,
(
unsigned
char
*
)
daemon
->
dhcp_buff
,
130
,
NULL
,
NULL
);
daemon
->
duid
=
safe_malloc
(
daemon
->
duid_len
);
memcpy
(
daemon
->
duid
,
daemon
->
dhcp_buff
,
daemon
->
duid_len
);
v6pass
=
1
;
goto
again
;
}
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
if
(
daemon
->
dhcp6
)
make_duid
(
now
);
}
#endif
#endif
#ifdef HAVE_SCRIPT
#ifdef HAVE_SCRIPT
...
@@ -727,7 +706,7 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *do
...
@@ -727,7 +706,7 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *do
if
(
!
(
lease_tmp
->
flags
&
(
LEASE_TA
|
LEASE_NA
)))
if
(
!
(
lease_tmp
->
flags
&
(
LEASE_TA
|
LEASE_NA
)))
continue
;
continue
;
/* another lease for the sa
em
DUID is OK for IPv6 */
/* another lease for the sa
me
DUID is OK for IPv6 */
if
(
lease
->
clid_len
==
lease_tmp
->
clid_len
&&
if
(
lease
->
clid_len
==
lease_tmp
->
clid_len
&&
lease
->
clid
&&
lease_tmp
->
clid
&&
lease
->
clid
&&
lease_tmp
->
clid
&&
memcmp
(
lease
->
clid
,
lease_tmp
->
clid
,
lease
->
clid_len
)
==
0
)
memcmp
(
lease
->
clid
,
lease_tmp
->
clid
,
lease
->
clid_len
)
==
0
)
...
@@ -865,6 +844,44 @@ int do_script_run(time_t now)
...
@@ -865,6 +844,44 @@ int do_script_run(time_t now)
return
0
;
/* nothing to do */
return
0
;
/* nothing to do */
}
}
#ifdef HAVE_SCRIPT
void
lease_add_extradata
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
data
,
unsigned
int
len
,
int
delim
)
{
unsigned
int
i
;
/* check for embeded NULLs */
for
(
i
=
0
;
i
<
len
;
i
++
)
if
(
data
[
i
]
==
0
)
{
len
=
i
;
break
;
}
if
((
lease
->
extradata_size
-
lease
->
extradata_len
)
<
(
len
+
1
))
{
size_t
newsz
=
lease
->
extradata_len
+
len
+
100
;
unsigned
char
*
new
=
whine_malloc
(
newsz
);
if
(
!
new
)
return
;
if
(
lease
->
extradata
)
{
memcpy
(
new
,
lease
->
extradata
,
lease
->
extradata_len
);
free
(
lease
->
extradata
);
}
lease
->
extradata
=
new
;
lease
->
extradata_size
=
newsz
;
}
if
(
len
!=
0
)
memcpy
(
lease
->
extradata
+
lease
->
extradata_len
,
data
,
len
);
lease
->
extradata
[
lease
->
extradata_len
+
len
]
=
delim
;
lease
->
extradata_len
+=
len
+
1
;
}
#endif
#endif
#endif
...
...
src/option.c
View file @
ceae00dd
...
@@ -1730,14 +1730,13 @@ static char *one_opt(int option, char *arg, char *gen_prob, int command_line)
...
@@ -1730,14 +1730,13 @@ static char *one_opt(int option, char *arg, char *gen_prob, int command_line)
local=/<domain>/
local=/<domain>/
local=/xxx.yyy.zzz.ip6.arpa/ */
local=/xxx.yyy.zzz.ip6.arpa/ */
if
(
strcmp
(
arg
,
"local"
)
!=
0
||
(
msize
&
4
!=
0
))
if
(
strcmp
(
arg
,
"local"
)
!=
0
||
(
(
msize
&
4
)
!=
0
))
option
=
'?'
;
option
=
'?'
;
else
else
{
{
struct
server
*
serv
=
opt_malloc
(
sizeof
(
struct
server
));
struct
server
*
serv
=
opt_malloc
(
sizeof
(
struct
server
));
in_addr_t
a
=
ntohl
(
new
->
start
.
s_addr
)
>>
8
;
char
*
p
;
char
*
p
;
memset
(
serv
,
0
,
sizeof
(
struct
server
));
memset
(
serv
,
0
,
sizeof
(
struct
server
));
serv
->
domain
=
d
;
serv
->
domain
=
d
;
serv
->
flags
=
SERV_HAS_DOMAIN
|
SERV_NO_ADDR
;
serv
->
flags
=
SERV_HAS_DOMAIN
|
SERV_NO_ADDR
;
...
...
src/rfc2131.c
View file @
ceae00dd
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#define option_ptr(opt, i) ((void *)&(((unsigned char *)(opt))[2u+(unsigned int)(i)]))
#define option_ptr(opt, i) ((void *)&(((unsigned char *)(opt))[2u+(unsigned int)(i)]))
#ifdef HAVE_SCRIPT
#ifdef HAVE_SCRIPT
static
void
add_extradata_data
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
data
,
size_t
len
,
int
delim
);
static
void
add_extradata_opt
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
opt
);
static
void
add_extradata_opt
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
opt
);
#endif
#endif
...
@@ -1252,7 +1251,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
...
@@ -1252,7 +1251,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
if
(
strcmp
(
n
->
net
,
n1
->
net
)
==
0
)
if
(
strcmp
(
n
->
net
,
n1
->
net
)
==
0
)
break
;
break
;
if
(
!
n1
)
if
(
!
n1
)
add_extradata_
data
(
lease
,
(
unsigned
char
*
)
n
->
net
,
strlen
(
n
->
net
),
n
->
next
?
' '
:
0
);
lease_add_extra
data
(
lease
,
(
unsigned
char
*
)
n
->
net
,
strlen
(
n
->
net
),
n
->
next
?
' '
:
0
);
}
}
if
((
opt
=
option_find
(
mess
,
sz
,
OPTION_USER_CLASS
,
1
)))
if
((
opt
=
option_find
(
mess
,
sz
,
OPTION_USER_CLASS
,
1
)))
...
@@ -1262,7 +1261,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
...
@@ -1262,7 +1261,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
/* If the user-class option started as counted strings, the first byte will be zero. */
/* If the user-class option started as counted strings, the first byte will be zero. */
if
(
len
!=
0
&&
ucp
[
0
]
==
0
)
if
(
len
!=
0
&&
ucp
[
0
]
==
0
)
ucp
++
,
len
--
;
ucp
++
,
len
--
;
add_extradata_
data
(
lease
,
ucp
,
len
,
0
);
lease_add_extra
data
(
lease
,
ucp
,
len
,
0
);
}
}
}
}
#endif
#endif
...
@@ -1484,51 +1483,12 @@ static int sanitise(unsigned char *opt, char *buf)
...
@@ -1484,51 +1483,12 @@ static int sanitise(unsigned char *opt, char *buf)
}
}
#ifdef HAVE_SCRIPT
#ifdef HAVE_SCRIPT
static
void
add_extradata_data
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
data
,
size_t
len
,
int
delim
)
{
if
((
lease
->
extradata_size
-
lease
->
extradata_len
)
<
(
len
+
1
))
{
size_t
newsz
=
lease
->
extradata_len
+
len
+
100
;
unsigned
char
*
new
=
whine_malloc
(
newsz
);
if
(
!
new
)
return
;
if
(
lease
->
extradata
)
{
memcpy
(
new
,
lease
->
extradata
,
lease
->
extradata_len
);
free
(
lease
->
extradata
);
}
lease
->
extradata
=
new
;
lease
->
extradata_size
=
newsz
;
}
if
(
len
!=
0
)
memcpy
(
lease
->
extradata
+
lease
->
extradata_len
,
data
,
len
);
lease
->
extradata
[
lease
->
extradata_len
+
len
]
=
delim
;
lease
->
extradata_len
+=
len
+
1
;
}
static
void
add_extradata_opt
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
opt
)
static
void
add_extradata_opt
(
struct
dhcp_lease
*
lease
,
unsigned
char
*
opt
)
{
{
if
(
!
opt
)
if
(
!
opt
)
add_extradata_
data
(
lease
,
NULL
,
0
,
0
);
lease_add_extra
data
(
lease
,
NULL
,
0
,
0
);
else
else
{
lease_add_extradata
(
lease
,
option_ptr
(
opt
,
0
),
option_len
(
opt
),
0
);
size_t
i
,
len
=
option_len
(
opt
);
unsigned
char
*
ucp
=
option_ptr
(
opt
,
0
);
/* check for embeded NULLs */
for
(
i
=
0
;
i
<
len
;
i
++
)
if
(
ucp
[
i
]
==
0
)
{
len
=
i
;
break
;
}
add_extradata_data
(
lease
,
ucp
,
len
,
0
);
}
}
}
#endif
#endif
...
...
src/rfc3315.c
View file @
ceae00dd
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment