1
1

Initial dump from Zyxel

This commit is contained in:
2026-04-17 17:00:52 +02:00
commit 81fec250f4
23116 changed files with 5231237 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,274 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2014-02-25 18:39:41.340090260 +0800
+++ udhcp-0.9.8/Makefile 2014-02-25 18:44:18.343352498 +0800
@@ -67,6 +67,10 @@
STRIP=$(CROSS_COMPILE)strip
endif
+#Sunrise customization
+ifneq ($(strip $(SUNRISE_DHCP_FORCE_RENEW)),)
+CFLAGS += -DSUNRISE_DHCP_FORCE_RENEW
+endif
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-02-25 18:39:41.340090260 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-02-25 18:47:30.601083125 +0800
@@ -80,6 +80,10 @@
extern int last_option_index;
#endif
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+char Forecerenewkey[128]="";
+#endif
+
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
struct client_config_t client_config = {
@@ -139,6 +143,9 @@
#if 1 /* vlan autohunt, ZyXEL, John */
" -V, --vid vlan auto hunt\n"
#endif
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+" -K, --renewkey Dhcp force renew key\n"
+#endif
);
exit(0);
}
@@ -294,6 +301,18 @@
int max_fd;
int sig;
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ char renewkey[128] = {0};
+ unsigned long replayDetectionNewh = 0 ;
+ unsigned long replayDetectionNewl = 0 ;
+ unsigned long replayDetectionOldh = 0 ;
+ unsigned long replayDetectionOldl = 0 ;
+ unsigned char authProtocol = 0;
+ unsigned char authAlgorithm = 0;
+ unsigned char authRDM = 0;
+ int isNew = FALSE;
+#endif
+
static struct option arg_options[] = {
#if 0 /* ZyXEL DHCP options support, ZyXEL, John */
{"clientid", required_argument, 0, 'c'},
@@ -314,6 +333,9 @@
#if 1 /* vlan autohunt, ZyXEL, John */
{"vid", required_argument, 0, 'V'},
#endif
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ {"renewkey", required_argument, 0, 'K'},
+#endif
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
};
@@ -323,7 +345,11 @@
/* get options */
while (1) {
int option_index = 0;
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:vV:C:I:SW:K:", arg_options, &option_index);
+#else
c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:vV:C:I:SW", arg_options, &option_index);
+#endif
if (c == -1) break;
switch (c) {
@@ -382,6 +408,11 @@
vlanId = atoi(optarg);
break;
#endif
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ case 'K':
+ strcpy(Forecerenewkey, optarg);
+ break;
+#endif
default:
show_usage();
}
@@ -572,11 +603,22 @@
DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring");
continue;
}
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ if (state != BOUND || *message != DHCPFORCERENEW)
+ {
+ if (packet.xid != xid) {
+ DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)",
+ (unsigned long) packet.xid, xid);
+ continue;
+ }
+ }
+#else
if (packet.xid != xid) {
DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)",
(unsigned long) packet.xid, xid);
continue;
}
+#endif
switch (state) {
case INIT_SELECTING:
@@ -629,7 +671,11 @@
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
state = BOUND;
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ change_mode(LISTEN_KERNEL);
+#else
change_mode(LISTEN_NONE);
+#endif
if (client_config.quit_after_lease)
exit_client(0);
if (!client_config.foreground)
@@ -650,6 +696,83 @@
}
break;
case BOUND:
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ if (*message == DHCPFORCERENEW)
+ {
+ printf("Receive DHCP_FORCE_RENEW\n");
+ if (!(temp = get_option(&packet, DHCP_AUTHENTICATION_INFO))) {
+ LOG(LOG_ERR, "No AUTHENTICATION INFO ");
+ }
+ else
+ {
+ memcpy(&authProtocol, temp, 1);
+ temp += 1;
+ memcpy(&authAlgorithm, temp, 1);
+ temp += 1;
+ memcpy(&authRDM, temp, 1);
+ temp += 1;
+ memcpy(&replayDetectionNewh, temp, 4);
+ replayDetectionNewh = ntohl(replayDetectionNewh);
+ temp += 4;
+ memcpy(&replayDetectionNewl, temp, 4);
+ replayDetectionNewl = ntohl(replayDetectionNewl);
+ temp += 4;
+
+ if ( authProtocol != 0 || authAlgorithm != 0 || authRDM != 0){
+ /*Should be Configuration token, RFC 3118 sec4*/
+ isNew = FALSE;
+ printf("Error ForceRenew packet (not Configuration token)\n");
+ }
+ else{
+ /*replay detection field MUST be a monotonically increasing value*/
+ if (replayDetectionOldh == 0 && replayDetectionOldl == 0)
+ {
+ isNew = TRUE;
+ replayDetectionOldh = replayDetectionNewh;
+ replayDetectionOldl = replayDetectionNewl;
+ }
+ else if (replayDetectionNewh > replayDetectionOldh)
+ {
+ isNew = TRUE;
+ replayDetectionOldh = replayDetectionNewh;
+ replayDetectionOldl = replayDetectionNewl;
+ }
+ else if (replayDetectionNewh == replayDetectionOldh && replayDetectionNewl > replayDetectionOldl)
+ {
+ isNew = TRUE;
+ replayDetectionOldh = replayDetectionNewh;
+ replayDetectionOldl = replayDetectionNewl;
+ }
+ else{
+ isNew = FALSE;
+ printf("Replay ForceRenew packet\n");
+ }
+ }
+
+ memcpy(&renewkey, temp, 12);
+ }
+
+ if (isNew){
+ if( !strcmp(Forecerenewkey, "") || !strcmp(Forecerenewkey, renewkey)) /* authentification match */
+ {
+ printf ("Forecerenewkey=%s renewkey=%s\n", Forecerenewkey, renewkey);
+ state = RENEWING;
+ change_mode(LISTEN_RAW);
+ DEBUG(LOG_INFO, "Entering renew state");
+ /* fall right through */
+ timeout = timeout - t1;
+#if 0 //random_xid
+ xid = random_xid();
+#endif
+ }
+ else
+ {
+ printf("Renewkey don't match\n");
+ }
+ isNew = FALSE;
+ }
+ }
+#endif
break;
case RELEASED:
/* case RELEASED: - ignore all packets */
Index: udhcp-0.9.8/dhcpd.h
===================================================================
--- udhcp-0.9.8.orig/dhcpd.h 2014-02-25 18:39:41.340090260 +0800
+++ udhcp-0.9.8/dhcpd.h 2014-02-25 18:44:37.933494941 +0800
@@ -66,6 +66,9 @@
#endif
#define DHCP_6RD_OPT 0xd4
#define DHCP_END 0xFF
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+#define DHCP_AUTHENTICATION_INFO 0x5a
+#endif
#define BOOTREQUEST 1
@@ -82,6 +85,9 @@
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCPINFORM 8
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+#define DHCPFORCERENEW 9
+#endif
#define BROADCAST_FLAG 0x8000
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2014-02-25 18:39:41.340090260 +0800
+++ udhcp-0.9.8/options.c 2014-02-25 18:43:49.383754113 +0800
@@ -49,6 +49,9 @@
{"tftp", OPTION_STRING, 0x42},
{"bootfile", OPTION_STRING, 0x43},
{"6rd", OPTION_STRING, DHCP_6RD_OPT},
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ {"forcerenew", OPTION_FORCERENEW, 0x5a},
+#endif
#if 1 /* DHCP option 43, 121(must be last two options in this array for implementation concerns), ZyXEL, John */
{"acsinfo", OPTION_STRING, 0x2b},
{"sroute", OPTION_STRING | OPTION_LIST, 0x79},
@@ -60,6 +63,9 @@
int option_lengths[] = {
[OPTION_IP] = 4,
[OPTION_IP_PAIR] = 8,
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ [OPTION_FORCERENEW] = 23,
+#endif
[OPTION_BOOLEAN] = 1,
[OPTION_STRING] = 1,
[OPTION_U8] = 1,
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2014-02-25 18:39:41.340090260 +0800
+++ udhcp-0.9.8/options.h 2014-02-25 18:43:35.838311989 +0800
@@ -9,6 +9,9 @@
enum {
OPTION_IP=1,
OPTION_IP_PAIR,
+#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
+ OPTION_FORCERENEW,
+#endif
OPTION_STRING,
OPTION_BOOLEAN,
OPTION_U8,
@@ -0,0 +1,49 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2014-02-25 18:48:43.168079367 +0800
+++ udhcp-0.9.8/Makefile 2014-02-25 18:50:51.667415521 +0800
@@ -71,6 +71,9 @@
ifneq ($(strip $(SUNRISE_DHCP_FORCE_RENEW)),)
CFLAGS += -DSUNRISE_DHCP_FORCE_RENEW
endif
+ifneq ($(strip $(SUNRISE_DHCP_OPTION58_OPTION59)),)
+CFLAGS += -DSUNRISE_DHCP_OPTION58_OPTION59
+endif
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-02-25 18:48:43.168079367 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-02-25 18:51:11.173429952 +0800
@@ -650,11 +650,30 @@
memcpy(&lease, temp, 4);
lease = ntohl(lease);
}
+#ifdef SUNRISE_DHCP_OPTION58_OPTION59 /*Support DHCP option for option 58 and 59*/
+ if (!(temp = get_option(&packet, DHCP_T1))) {
+ LOG(LOG_ERR, "No Renewal time with ACK, using leasetime/2");
+ t1 = lease / 2;
+ }
+ else {
+ memcpy(&t1, temp, 4);
+ t1 = ntohl(t1);
+ }
+ if (!(temp = get_option(&packet, DHCP_T2))) {
+ LOG(LOG_ERR, "No Rebinding time with ACK, using (leasetime*0.875)");
+ t2 = (lease * 0x7) >> 3;
+ }
+ else {
+ memcpy(&t2, temp, 4);
+ t2 = ntohl(t2);
+ }
+#else
/* enter bound state */
t1 = lease / 2;
/* little fixed point for n * .875 */
t2 = (lease * 0x7) >> 3;
+#endif
temp_addr.s_addr = packet.yiaddr;
LOG(LOG_INFO, "Lease of %s obtained, lease time %ld",
inet_ntoa(temp_addr), lease);
@@ -0,0 +1,28 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2014-02-25 18:52:08.312075243 +0800
+++ udhcp-0.9.8/Makefile 2014-02-25 18:53:37.148801264 +0800
@@ -74,6 +74,9 @@
ifneq ($(strip $(SUNRISE_DHCP_OPTION58_OPTION59)),)
CFLAGS += -DSUNRISE_DHCP_OPTION58_OPTION59
endif
+ifneq ($(strip $(SUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN)),)
+CFLAGS += -DSUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN
+endif
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-02-25 18:52:08.312075243 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-02-25 18:53:55.141578263 +0800
@@ -816,6 +816,9 @@
break;
case SIGTERM:
LOG(LOG_INFO, "Received SIGTERM");
+#ifdef SUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN
+ perform_release();
+#endif
exit_client(0);
}
} else if (retval == -1 && errno == EINTR) {
@@ -0,0 +1,46 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-03-13 18:18:55.946177588 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-03-13 18:22:38.318791100 +0800
@@ -53,6 +53,9 @@
#include <json/json.h>
+#include <sys/sysinfo.h>
+struct sysinfo sysinfoObject;
+
static int state;
static unsigned long requested_ip; /* = 0 */
static unsigned long server_addr;
@@ -101,6 +104,13 @@
arp: "\0\0\0\0\0\0", /* appease gcc-3.0 */
};
+
+unsigned long getUptime()
+{
+ sysinfo(&sysinfoObject);
+ return sysinfoObject.uptime;
+}
+
int daemon_init(void) {
pid_t pid;
@@ -451,7 +461,7 @@
for (;;) {
- tv.tv_sec = timeout - time(0);
+ tv.tv_sec = timeout - getUptime();
tv.tv_usec = 0;
FD_ZERO(&rfds);
@@ -474,7 +484,7 @@
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
} else retval = 0; /* If we already timed out, fall through */
- now = time(0);
+ now = getUptime();
if (retval == 0) {
/* timeout dropped to zero */
switch (state) {
@@ -0,0 +1,93 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-03-20 17:01:52.958585144 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-03-20 17:05:37.365847400 +0800
@@ -439,7 +439,7 @@
exit_client(1);
#if 1 /* ZyXEL DHCP options support, ZyXEL, John */
- read_config_options();
+ read_config_options(client_config.interface);
#else
if (!client_config.clientid) {
client_config.clientid = xmalloc(6 + 3);
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2014-03-20 17:01:52.930585145 +0800
+++ udhcp-0.9.8/options.c 2014-03-20 17:06:37.518375500 +0800
@@ -282,17 +282,50 @@
}
}
-int read_config_options()
+int read_config_options(const char* intfName)
{
rdm_Dhcpv4ReqOpt_t *reqOptObj = NULL;
rdm_Dhcpv4SentOpt_t *sentOptObj = NULL;
objIndex_t optIid;
+ rdm_IpIface_t *ipIface = NULL;
+ rdm_Dhcpv4Client_t *dhcpcObj = NULL;
+ objIndex_t ipIfaceIid;
+ objIndex_t dhcpIid;
+ char ipIntf[256] = "";
+ int found = 0;
zcfgRet_t ret = ZCFG_SUCCESS;
char hexOpt[256];
-
+
+ //find ip.interface via interface name
+ IID_INIT(ipIfaceIid);
+ while(zcfgFeObjStructGetNext(RDM_OID_IP_IFACE, &ipIfaceIid, (void **)&ipIface) == ZCFG_SUCCESS) {
+ if ( !strcmp(ipIface->X_ZYXEL_IfName, intfName) ){
+ sprintf(ipIntf, "IP.Interface.%d", ipIfaceIid.idx[0]);
+ free(ipIface);
+ break;
+ }
+ free(ipIface);
+ }
+
+ if (strlen(ipIntf) == 0)//can't find corresponding ip interface
+ return 0;
+
+ IID_INIT(dhcpIid);
+ while(zcfgFeObjStructGetNext(RDM_OID_DHCPV4_CLIENT, &dhcpIid, (void **)&dhcpcObj) == ZCFG_SUCCESS) {
+ if ( !strcmp(dhcpcObj->Interface, ipIntf) ){
+ found = 1;
+ free(ipIface);
+ break;
+ }
+ else
+ free(ipIface);
+ }
+
+ if (found == 0)
+ return 0;
IID_INIT(optIid);
- while((ret = zcfgFeObjStructGetNext(RDM_OID_DHCPV4_REQ_OPT, &optIid, (void **)&reqOptObj)) == ZCFG_SUCCESS){
+ while((ret = zcfgFeSubInStructGetNext(RDM_OID_DHCPV4_REQ_OPT, &dhcpIid, &optIid, (void **)&reqOptObj)) == ZCFG_SUCCESS){
if(reqOptObj->Enable){
if(reqOptObj->Tag == DHCP_6RD_OPT) {
options[last_option_index - 3].flags |= OPTION_REQ;
@@ -313,7 +346,7 @@
sent_config_options[0] = DHCP_END;
IID_INIT(optIid);
- while((ret = zcfgFeObjStructGetNext(RDM_OID_DHCPV4_SENT_OPT, &optIid, (void **)&sentOptObj)) == ZCFG_SUCCESS){
+ while((ret = zcfgFeSubInStructGetNext(RDM_OID_DHCPV4_SENT_OPT, &dhcpIid, &optIid, (void **)&sentOptObj)) == ZCFG_SUCCESS){
if(sentOptObj->Enable){
hexStringToOption(sentOptObj->Value, hexOpt);
add_option_string(sent_config_options, (unsigned char *)hexOpt);
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2014-03-20 17:01:52.930585145 +0800
+++ udhcp-0.9.8/options.h 2014-03-20 17:06:52.983968000 +0800
@@ -68,7 +68,7 @@
#if 1 /* ZyXEL DHCP option support (porting from BRCM and MSTC), John */
void hexOptionToString(char *hexOpt, char *hexStr);
void hexStringToOption(char * hexStr,char * hexOpt);
-int read_config_options(void);
+int read_config_options(const char* intfName);
#endif
@@ -0,0 +1,45 @@
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2014-04-15 14:33:54.226324346 +0800
+++ udhcp-0.9.8/options.c 2014-04-15 14:39:26.674321894 +0800
@@ -311,20 +311,22 @@
return 0;
IID_INIT(dhcpIid);
+
while(zcfgFeObjStructGetNext(RDM_OID_DHCPV4_CLIENT, &dhcpIid, (void **)&dhcpcObj) == ZCFG_SUCCESS) {
if ( !strcmp(dhcpcObj->Interface, ipIntf) ){
found = 1;
- free(ipIface);
+ free(dhcpcObj);
break;
}
else
- free(ipIface);
+ free(dhcpcObj);
}
if (found == 0)
return 0;
IID_INIT(optIid);
+
while((ret = zcfgFeSubInStructGetNext(RDM_OID_DHCPV4_REQ_OPT, &dhcpIid, &optIid, (void **)&reqOptObj)) == ZCFG_SUCCESS){
if(reqOptObj->Enable){
if(reqOptObj->Tag == DHCP_6RD_OPT) {
@@ -346,13 +348,14 @@
sent_config_options[0] = DHCP_END;
IID_INIT(optIid);
+
while((ret = zcfgFeSubInStructGetNext(RDM_OID_DHCPV4_SENT_OPT, &dhcpIid, &optIid, (void **)&sentOptObj)) == ZCFG_SUCCESS){
if(sentOptObj->Enable){
hexStringToOption(sentOptObj->Value, hexOpt);
add_option_string(sent_config_options, (unsigned char *)hexOpt);
optLen += hexOpt[1] + 2;
}
- zcfgFeObjStructFree(reqOptObj);
+ zcfgFeObjStructFree(sentOptObj);
}
return 0;
@@ -0,0 +1,164 @@
Index: udhcp-0.9.8/clientpacket.c
===================================================================
--- udhcp-0.9.8.orig/clientpacket.c 2014-04-30 18:23:08.120670171 +0800
+++ udhcp-0.9.8/clientpacket.c 2014-04-29 14:12:47.908997200 +0800
@@ -152,7 +152,7 @@
/* Unicasts or broadcasts a DHCP renew message */
-int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
+int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr, char *inf)
{
struct dhcpMessage packet;
int ret = 0;
@@ -164,7 +164,7 @@
add_requests(&packet);
LOG(LOG_DEBUG, "Sending renew...");
if (server)
- ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
+ ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT, inf);
else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
return ret;
@@ -172,7 +172,7 @@
/* Unicasts a DHCP release message */
-int send_release(unsigned long server, unsigned long ciaddr)
+int send_release(unsigned long server, unsigned long ciaddr, char *inf)
{
struct dhcpMessage packet;
@@ -184,7 +184,7 @@
add_simple_option(packet.options, DHCP_SERVER_ID, server);
LOG(LOG_DEBUG, "Sending release...");
- return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
+ return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT, inf);
}
Index: udhcp-0.9.8/clientpacket.h
===================================================================
--- udhcp-0.9.8.orig/clientpacket.h 2001-08-11 09:30:47.000000000 +0800
+++ udhcp-0.9.8/clientpacket.h 2014-04-29 14:28:05.446011800 +0800
@@ -4,9 +4,9 @@
unsigned long random_xid(void);
int send_discover(unsigned long xid, unsigned long requested);
int send_selecting(unsigned long xid, unsigned long server, unsigned long requested);
-int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
-int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
-int send_release(unsigned long server, unsigned long ciaddr);
+int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr, char *inf);
+int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr, char *inf);
+int send_release(unsigned long server, unsigned long ciaddr, char *inf);
int get_raw_packet(struct dhcpMessage *payload, int fd);
#endif
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-04-30 18:23:08.168670171 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-04-29 14:26:36.072286600 +0800
@@ -239,7 +239,7 @@
json_object_put(dhcpc_opt);
#endif
- send_release(server_addr, requested_ip); /* unicast */
+ send_release(server_addr, requested_ip, client_config.interface); /* unicast */
run_script(NULL, "deconfig");
}
@@ -516,7 +516,7 @@
if (packet_num < 3) {
/* send request packet */
if (state == RENEW_REQUESTED)
- send_renew(xid, server_addr, requested_ip); /* unicast */
+ send_renew(xid, server_addr, requested_ip, client_config.interface); /* unicast */
else send_selecting(xid, server_addr, requested_ip); /* broadcast */
timeout = now + ((packet_num == 2) ? 10 : 2);
@@ -545,7 +545,7 @@
DEBUG(LOG_INFO, "Entering rebinding state");
} else {
/* send a request packet */
- send_renew(xid, server_addr, requested_ip); /* unicast */
+ send_renew(xid, server_addr, requested_ip, client_config.interface); /* unicast */
t1 = (t2 - t1) / 2 + t1;
timeout = t1 + start;
@@ -585,7 +585,7 @@
change_mode(LISTEN_RAW);
} else {
/* send a request packet */
- send_renew(xid, 0, requested_ip); /* broadcast */
+ send_renew(xid, 0, requested_ip, client_config.interface); /* broadcast */
t2 = (lease - t2) / 2 + t2;
timeout = t2 + start;
Index: udhcp-0.9.8/packet.c
===================================================================
--- udhcp-0.9.8.orig/packet.c 2002-08-28 02:23:14.000000000 +0800
+++ udhcp-0.9.8/packet.c 2014-04-29 14:04:50.191959800 +0800
@@ -13,6 +13,7 @@
#include <linux/if_ether.h>
#endif
#include <errno.h>
+#include <net/if.h>
#include "packet.h"
#include "debug.h"
@@ -168,11 +169,12 @@
/* Let the kernel do all the work for packet generation */
int kernel_packet(struct dhcpMessage *payload, u_int32_t source_ip, int source_port,
- u_int32_t dest_ip, int dest_port)
+ u_int32_t dest_ip, int dest_port, char *inf)
{
int n = 1;
int fd, result;
struct sockaddr_in client;
+ struct ifreq boundIf;
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
return -1;
@@ -180,6 +182,14 @@
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1)
return -1;
+ // need to bind interface in unicast case, must co-operate with iptables and routing table
+ if ( inf != NULL && strlen(inf) > 0){
+ strncpy(boundIf.ifr_name, inf, IFNAMSIZ);
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,(char *)&boundIf, sizeof(boundIf)) < 0) {
+ DEBUG(LOG_INFO, "dhcpc bind to %s fail", inf);
+ }
+ }
+
memset(&client, 0, sizeof(client));
client.sin_family = AF_INET;
client.sin_port = htons(source_port);
Index: udhcp-0.9.8/packet.h
===================================================================
--- udhcp-0.9.8.orig/packet.h 2002-04-03 06:49:33.000000000 +0800
+++ udhcp-0.9.8/packet.h 2014-04-29 14:25:21.945248100 +0800
@@ -35,7 +35,7 @@
int raw_packet(struct dhcpMessage *payload, u_int32_t source_ip, int source_port,
u_int32_t dest_ip, int dest_port, unsigned char *dest_arp, int ifindex);
int kernel_packet(struct dhcpMessage *payload, u_int32_t source_ip, int source_port,
- u_int32_t dest_ip, int dest_port);
+ u_int32_t dest_ip, int dest_port, char *inf);
#endif
Index: udhcp-0.9.8/serverpacket.c
===================================================================
--- udhcp-0.9.8.orig/serverpacket.c 2002-04-03 06:49:33.000000000 +0800
+++ udhcp-0.9.8/serverpacket.c 2014-04-29 14:25:06.075687200 +0800
@@ -37,7 +37,7 @@
DEBUG(LOG_INFO, "Forwarding packet to relay");
return kernel_packet(payload, server_config.server, SERVER_PORT,
- payload->giaddr, SERVER_PORT);
+ payload->giaddr, SERVER_PORT, NULL);
}
@@ -0,0 +1,64 @@
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2014-05-13 14:53:46.912467742 +0800
+++ udhcp-0.9.8/script.c 2014-05-13 14:56:21.825124327 +0800
@@ -213,7 +213,11 @@
/* put all the paramaters into an environment */
+#if 1 //ZYXEL__, Mark
+static char **fill_envp(struct dhcpMessage *packet, char *name)
+#else
static char **fill_envp(struct dhcpMessage *packet)
+#endif
{
int num_options = 0;
int i, j;
@@ -226,6 +230,9 @@
struct json_object *dhcpc_opt = NULL;
const char *payload = NULL;
int payloadLen = 0;
+#if 1
+ int msgType = ZCFG_MSG_DHCPC_BOUND;
+#endif
if (packet == NULL)
num_options = 0;
@@ -297,8 +304,12 @@
payload = json_object_to_json_string(dhcpc_opt);
payloadLen = strlen(payload) + 1;
+#if 1 //__ZYXEL__, Mark
+ msgType = (name && strcmp(name, "renew") == 0) ? ZCFG_MSG_DHCPC_RENEW : ZCFG_MSG_DHCPC_BOUND;
+ dhcpMsgSend(msgType, ZCFG_EID_ESMD, payloadLen, payload);
+#else
dhcpMsgSend(ZCFG_MSG_DHCPC_BOUND, ZCFG_EID_ESMD, payloadLen, payload);
-
+#endif
json_object_put(dhcpc_opt);
//envp[j] = NULL;
@@ -316,7 +327,11 @@
#endif
if (strcmp(name, "bound") == 0 || strcmp(name, "renew") == 0) {
//envp = fill_envp(packet);
+#if 1 //__ZYXEL__, Mark
+ fill_envp(packet, name);
+#else
fill_envp(packet);
+#endif
#if 0
while(*envp != NULL) {
free(*envp);
@@ -340,7 +355,11 @@
waitpid(pid, NULL, 0);
return;
} else if (pid == 0) {
+#if 1 //__ZYXEL__, Mark
+ envp = fill_envp(packet, name);
+#else
envp = fill_envp(packet);
+#endif
/* close fd's? */
@@ -0,0 +1,18 @@
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2014-05-26 09:11:35.616950655 +0800
+++ udhcp-0.9.8/options.c 2014-05-26 09:16:11.594877176 +0800
@@ -48,10 +48,12 @@
{"message", OPTION_STRING, 0x38},
{"tftp", OPTION_STRING, 0x42},
{"bootfile", OPTION_STRING, 0x43},
- {"6rd", OPTION_STRING, DHCP_6RD_OPT},
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
{"forcerenew", OPTION_FORCERENEW, 0x5a},
#endif
+/* Pochao: keep the following three options in order,
+ since the function read_config_options will check these options by the order in the array*/
+ {"6rd", OPTION_STRING, DHCP_6RD_OPT},
#if 1 /* DHCP option 43, 121(must be last two options in this array for implementation concerns), ZyXEL, John */
{"acsinfo", OPTION_STRING, 0x2b},
{"sroute", OPTION_STRING | OPTION_LIST, 0x79},
@@ -0,0 +1,54 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2014-09-25 13:41:51.774447660 +0800
+++ udhcp-0.9.8/Makefile 2014-09-25 13:41:51.958447658 +0800
@@ -77,6 +77,9 @@
ifneq ($(strip $(SUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN)),)
CFLAGS += -DSUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN
endif
+ifneq ($(strip $(SUNRISE_VLANHUNT_CUSTOMIZATION)),)
+CFLAGS += -DSUNRISE_VLANHUNT_CUSTOMIZATION
+endif
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2014-09-25 13:41:51.866447659 +0800
+++ udhcp-0.9.8/dhcpc.c 2014-09-25 13:43:10.746533268 +0800
@@ -634,6 +634,21 @@
case INIT_SELECTING:
/* Must be a DHCPOFFER to one of our xid's */
if (*message == DHCPOFFER) {
+#ifdef SUNRISE_VLANHUNT_CUSTOMIZATION
+ temp = get_option(&packet, 0x2b);
+ if(vlanId != -1){
+ if (temp != NULL)
+ dhcpMsgSend(ZCFG_MSG_VLAN_HUNT_SUCCESS, ZCFG_EID_VLAN_AUTOHUNT, 0, NULL);
+ else
+ dhcpMsgSend(ZCFG_MSG_VLAN_HUNT_TERMINATE, ZCFG_EID_VLAN_AUTOHUNT, 0, NULL);
+ exit_client(0);
+ }
+ if ( (options[last_option_index - 2].flags & OPTION_REQ) && temp == NULL && strstr(client_config.interface, "eth") ){
+ DEBUG(LOG_ERR, "Reveive DHCP OFFER without option43 on Eth interface: %s", client_config.interface);
+ DEBUG(LOG_ERR, "Stop dhcp");
+ exit_client(0);
+ }
+#endif
if ((temp = get_option(&packet, DHCP_SERVER_ID))) {
memcpy(&server_addr, temp, 4);
xid = packet.xid;
@@ -691,11 +706,13 @@
timeout = t1 + start;
requested_ip = packet.yiaddr;
#if 1 /* vlan autohunt, ZyXEL, John */
+#ifndef SUNRISE_VLANHUNT_CUSTOMIZATION
if(vlanId != -1){
dhcpMsgSend(ZCFG_MSG_VLAN_HUNT_SUCCESS, ZCFG_EID_VLAN_AUTOHUNT, 0, NULL);
exit_client(0);
}
#endif
+#endif
run_script(&packet,
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
@@ -0,0 +1,79 @@
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2014-12-03 14:30:50.658378978 +0800
+++ udhcp-0.9.8/options.c 2014-12-03 14:30:50.706378978 +0800
@@ -51,7 +51,8 @@
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
{"forcerenew", OPTION_FORCERENEW, 0x5a},
#endif
-/* Pochao: keep the following three options in order,
+ {"sipsrv", OPTION_STRING, 0x78}, //Keep following four option in order
+ /* Pochao: keep the following three options in order,
since the function read_config_options will check these options by the order in the array*/
{"6rd", OPTION_STRING, DHCP_6RD_OPT},
#if 1 /* DHCP option 43, 121(must be last two options in this array for implementation concerns), ZyXEL, John */
@@ -331,6 +332,11 @@
while((ret = zcfgFeSubInStructGetNext(RDM_OID_DHCPV4_REQ_OPT, &dhcpIid, &optIid, (void **)&reqOptObj)) == ZCFG_SUCCESS){
if(reqOptObj->Enable){
+
+ if(reqOptObj->Tag == 120) {//option120
+ options[last_option_index - 4].flags |= OPTION_REQ;
+ }
+
if(reqOptObj->Tag == DHCP_6RD_OPT) {
options[last_option_index - 3].flags |= OPTION_REQ;
}
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2014-12-03 14:30:50.638378978 +0800
+++ udhcp-0.9.8/script.c 2014-12-03 14:43:53.862373200 +0800
@@ -181,6 +181,37 @@
sprintf(brAddr, "%d.%d.%d.%d", option[18], option[19], option[20], option[21]);
json_object_object_add(dhcpc_opt, "brAddr", json_object_new_string(brAddr));
+ }else if(type_p->code == 0x78){ //option 120 SIP Server
+ //printf("OPTION 120!!");
+ //printf("%d %d %d %d %d %d", *(option - 1), option[0], option[1], option[2], option[3], option[4]);
+ u_int8_t op120_total_len = *(option - 1);
+ char sip_svr_addr[257];
+ char *svr_addr_ptr = sip_svr_addr;
+ char *payload = option + 1;
+ if(option[0] == 0){ //Domain
+
+ while(payload < (option + op120_total_len)){
+ u_int8_t sub_str_len = *payload++;
+
+ strncpy(svr_addr_ptr, payload, sub_str_len);
+ svr_addr_ptr += sub_str_len;
+ payload += sub_str_len;
+
+ if(*payload != 0){
+ *svr_addr_ptr = '.';
+ }else{
+ *svr_addr_ptr = '\0';
+ break;
+ }
+ svr_addr_ptr++;
+
+ }
+
+ }else if(option[0] == 1){ //IP-Address
+ sprintf(sip_svr_addr, "%d.%d.%d.%d", option[1], option[2], option[3], option[4]);
+ }
+ //printf("type_p->name:%s\n", type_p->name);
+ json_object_object_add(dhcpc_opt, type_p->name, json_object_new_string(sip_svr_addr));
}
#endif
memcpy(dest, option, len);
@@ -304,6 +335,10 @@
payload = json_object_to_json_string(dhcpc_opt);
payloadLen = strlen(payload) + 1;
+
+ //printf("============================UDHCP===========================\n");
+ //printf("%s\n", payload);
+
#if 1 //__ZYXEL__, Mark
msgType = (name && strcmp(name, "renew") == 0) ? ZCFG_MSG_DHCPC_RENEW : ZCFG_MSG_DHCPC_BOUND;
dhcpMsgSend(msgType, ZCFG_EID_ESMD, payloadLen, payload);
@@ -0,0 +1,36 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2015-02-13 18:40:58.069634896 +0800
+++ udhcp-0.9.8/dhcpc.c 2015-02-13 18:47:56.632678166 +0800
@@ -733,6 +733,31 @@
run_script(&packet, "nak");
if (state != REQUESTING)
run_script(NULL, "deconfig");
+
+#if 1 /* renew fail, send ZCFG_MSG_WAN_CONNECTION_LOST to ESMD for notification*/
+ if (state == REBINDING){
+ char ip[16] = {0};
+ unsigned char *tmpIp;
+ struct json_object *dhcpc_opt = NULL;
+ const char *payload = NULL;
+ int payloadLen = 0;
+
+ dhcpc_opt = json_object_new_object();
+ tmpIp = (unsigned char *) &requested_ip;
+ sprintf(ip, "%d.%d.%d.%d", tmpIp[0], tmpIp[1], tmpIp[2], tmpIp[3]);
+ json_object_object_add(dhcpc_opt, "ip", json_object_new_string(ip));
+
+ json_object_object_add(dhcpc_opt, "addressAssigned", json_object_new_boolean(false));
+ json_object_object_add(dhcpc_opt, "pidfile", json_object_new_string(client_config.pidfile));
+
+ payload = json_object_to_json_string(dhcpc_opt);
+
+ payloadLen = strlen(payload) + 1;
+ dhcpMsgSend(ZCFG_MSG_DHCPC_RELEASE, ZCFG_EID_ESMD, payloadLen, payload);
+ json_object_put(dhcpc_opt);
+ }
+#endif
+
state = INIT_SELECTING;
timeout = now;
requested_ip = 0;
@@ -0,0 +1,30 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2015-04-02 10:57:59.411709307 +0800
+++ udhcp-0.9.8/dhcpc.c 2015-04-02 11:01:13.330698800 +0800
@@ -51,6 +51,10 @@
#include "zcfg_fe_rdm_access.h"
#include "zcfg_msg.h"
+#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
+#include <math.h>
+#endif
+
#include <json/json.h>
#include <sys/sysinfo.h>
@@ -493,6 +497,14 @@
if (packet_num == 0)
xid = random_xid();
+#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
+ int j;
+ xid = xid / 1000000;
+ for(j = 4; j < 6; j++ ){
+ xid = xid * 1000 + (unsigned int)client_config.arp[j];
+ }
+#endif
+
/* send discover packet */
send_discover(xid, requested_ip); /* broadcast */
@@ -0,0 +1,59 @@
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2016-01-11 13:47:28.185584933 +0800
+++ udhcp-0.9.8/script.c 2016-01-12 10:13:39.720872422 +0800
@@ -93,6 +93,26 @@
return ret;
}
+bool getDefaultRouteFromOption121(unsigned char *option, char *gateway){
+ int i = 0;
+ int dest_len_byte = 0;
+
+ i = OPT_DATA;
+ while(i < option[OPT_LEN] + 2){
+ if(option[i] == 0){
+ sprintf(gateway, "%d.%d.%d.%d", option[i+1], option[i+2], option[i+3], option[i+4]);
+ return true;
+ }
+ else{
+ dest_len_byte = option[i]/8 + ((option[i]%8 != 0)?1:0);
+ i = i + 1 + dest_len_byte + 4;
+ }
+ }
+
+ return false;
+}
+
+
static int upper_length(int length, struct dhcp_option *option)
{
return max_option_length[option->flags & TYPE_MASK] *
@@ -161,6 +181,12 @@
#if 1 /* ZyXEL DHCP option support (porting from BRCM and MSTC), John */
/* DHCP option 43 */
if(type_p->code == 0x2b || type_p->code == 0x79){
+ if(type_p->code == 0x79){
+ //RFC3442, if option 121 contain default route, the priority is higher than option3.
+ if(getDefaultRouteFromOption121((char *)(option - 2), optStr) == true)
+ json_object_object_add(dhcpc_opt, "router", json_object_new_string(optStr));
+ }
+
hexOptionToString((char *)(option - 2), optStr);
json_object_object_add(dhcpc_opt, type_p->name, json_object_new_string(optStr));
}
@@ -307,6 +333,14 @@
}
}
+ //if there is no option 3 or no default route in option121, get giaddr as router ip
+ if(json_object_object_get(dhcpc_opt, "router") == NULL){
+ tmpIp = (unsigned char *) &packet->giaddr;
+ sprintf(ip, "%d.%d.%d.%d", tmpIp[0], tmpIp[1], tmpIp[2], tmpIp[3]);
+ json_object_object_add(dhcpc_opt, "router", json_object_new_string(ip));
+ printf("dhcp msg giaddr =%s\n", ip);
+ }
+
if (packet->siaddr) {
//envp[j] = xmalloc(sizeof("siaddr=255.255.255.255"));
//sprintip(envp[j++], "siaddr=", (unsigned char *) &packet->siaddr);
@@ -0,0 +1,65 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2016-02-15 13:34:33.879577698 +0800
+++ udhcp-0.9.8/dhcpc.c 2016-02-15 14:30:26.475169277 +0800
@@ -207,7 +207,7 @@
}
/* perform a release */
-static void perform_release(void)
+static void perform_release(int notifyEsmd)
{
char buffer[16];
struct in_addr temp_addr;
@@ -227,21 +227,22 @@
LOG(LOG_INFO, "Unicasting a release of %s to %s",
inet_ntoa(temp_addr), buffer);
#if 1 /* send ZCFG_MSG_DHCP_RELEASE to ESMD for notification, ZyXEL, John */
- dhcpc_opt = json_object_new_object();
+ if(notifyEsmd){
+ dhcpc_opt = json_object_new_object();
- tmpIp = (unsigned char *) &requested_ip;
- sprintf(ip, "%d.%d.%d.%d", tmpIp[0], tmpIp[1], tmpIp[2], tmpIp[3]);
- json_object_object_add(dhcpc_opt, "ip", json_object_new_string(ip));
-
- json_object_object_add(dhcpc_opt, "addressAssigned", json_object_new_boolean(false));
- json_object_object_add(dhcpc_opt, "pidfile", json_object_new_string(client_config.pidfile));
-
- payload = json_object_to_json_string(dhcpc_opt);
-
- payloadLen = strlen(payload) + 1;
- dhcpMsgSend(ZCFG_MSG_DHCPC_RELEASE, ZCFG_EID_ESMD, payloadLen, payload);
- json_object_put(dhcpc_opt);
-
+ tmpIp = (unsigned char *) &requested_ip;
+ sprintf(ip, "%d.%d.%d.%d", tmpIp[0], tmpIp[1], tmpIp[2], tmpIp[3]);
+ json_object_object_add(dhcpc_opt, "ip", json_object_new_string(ip));
+
+ json_object_object_add(dhcpc_opt, "addressAssigned", json_object_new_boolean(false));
+ json_object_object_add(dhcpc_opt, "pidfile", json_object_new_string(client_config.pidfile));
+
+ payload = json_object_to_json_string(dhcpc_opt);
+
+ payloadLen = strlen(payload) + 1;
+ dhcpMsgSend(ZCFG_MSG_DHCPC_RELEASE, ZCFG_EID_ESMD, payloadLen, payload);
+ json_object_put(dhcpc_opt);
+ }
#endif
send_release(server_addr, requested_ip, client_config.interface); /* unicast */
@@ -876,12 +877,12 @@
perform_renew();
break;
case SIGUSR2:
- perform_release();
+ perform_release(1);
break;
case SIGTERM:
LOG(LOG_INFO, "Received SIGTERM");
#ifdef SUNRISE_RELEASE_DHCP_PPP_BEFORE_IFDOWN
- perform_release();
+ perform_release(0);
#endif
exit_client(0);
}
@@ -0,0 +1,77 @@
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2016-03-15 16:02:32.491074852 +0800
+++ udhcp-0.9.8/options.c 2016-03-15 16:07:10.936951700 +0800
@@ -298,6 +298,7 @@
int found = 0;
zcfgRet_t ret = ZCFG_SUCCESS;
char hexOpt[256];
+ int idx=-1;
//find ip.interface via interface name
IID_INIT(ipIfaceIid);
@@ -348,6 +349,12 @@
if(reqOptObj->Tag == 0x79){
options[last_option_index - 1].flags |= OPTION_REQ;
}
+
+ if(reqOptObj->Tag == DHCP_NTP_SERVER){
+ idx = find_dhcp_options(DHCP_NTP_SERVER);
+ if(idx != -1)
+ { options[idx].flags |= OPTION_REQ; }
+ }
}
zcfgFeObjStructFree(reqOptObj);
@@ -368,4 +375,21 @@
return 0;
}
+
+/*find option 'code' in options*/
+int find_dhcp_options(char code)
+{
+ int i = 0;
+ while(i < last_option_index)
+ {
+ if(options[i].code == code)
+ { break; }
+ i++;
+ }
+
+ if(i == last_option_index)
+ { i=-1; }
+
+ return i ;
+}
#endif
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2016-03-15 16:02:32.443050846 +0800
+++ udhcp-0.9.8/options.h 2016-03-15 16:05:36.396047300 +0800
@@ -69,6 +69,7 @@
void hexOptionToString(char *hexOpt, char *hexStr);
void hexStringToOption(char * hexStr,char * hexOpt);
int read_config_options(const char* intfName);
+int find_dhcp_options(char code);
#endif
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2016-03-15 16:02:32.519088851 +0800
+++ udhcp-0.9.8/script.c 2016-03-15 16:06:14.567680100 +0800
@@ -153,6 +153,13 @@
option += 4;
optlen = 4;
case OPTION_IP: /* Works regardless of host byte order. */
+ if(type_p->code == DHCP_NTP_SERVER)
+ {
+ char ntpsrv_addr[16];
+
+ sprintf(ntpsrv_addr, "%d.%d.%d.%d", option[0], option[1], option[2], option[3]);
+ json_object_object_add(dhcpc_opt, type_p->name, json_object_new_string(ntpsrv_addr));
+ }
dest += sprintip(dest, "", option);
break;
case OPTION_BOOLEAN:
@@ -0,0 +1,21 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c
+++ udhcp-0.9.8/dhcpc.c
@@ -90,6 +90,7 @@ extern int last_option_index;
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
char Forecerenewkey[128]="";
#endif
+#define INIT_TIMEOUT 5
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
@@ -521,7 +522,7 @@ int main(int argc, char *argv[])
}
/* wait to try again */
packet_num = 0;
- timeout = now + 60;
+ timeout = now + INIT_TIMEOUT;
}
break;
case RENEW_REQUESTED:
@@ -0,0 +1,20 @@
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2016-04-27 17:03:38.299144952 +0800
+++ udhcp-0.9.8/script.c 2016-04-27 17:06:32.482523557 +0800
@@ -208,8 +208,13 @@
json_object_object_add(dhcpc_opt, "v6PrefixLen", json_object_new_int((int)option[1]));
ptr16 = (uint16_t*)&option[2];
-
- sprintf(prefix, "%x:%x:%x:%x:%x:%x:%x:%x", ptr16[0], ptr16[1], ptr16[2], ptr16[3], ptr16[4], ptr16[5], ptr16[6], ptr16[7]);
+
+/*__ZYXEL__, ChiHsiang 6RD prefix has endian issue, if cpu is little endian and do not use ntohs() will creat wrong prefix.*/
+// sprintf(prefix, "%x:%x:%x:%x:%x:%x:%x:%x", ptr16[0], ptr16[1], ptr16[2], ptr16[3], ptr16[4], ptr16[5], ptr16[6], ptr16[7]);
+ sprintf(prefix, "%x:%x:%x:%x:%x:%x:%x:%x", ntohs(ptr16[0]), ntohs(ptr16[1]), ntohs(ptr16[2]),
+ ntohs(ptr16[3]), ntohs(ptr16[4]), ntohs(ptr16[5]),
+ ntohs(ptr16[6]), ntohs(ptr16[7]));
+
json_object_object_add(dhcpc_opt, "v6Prefix", json_object_new_string(prefix));
sprintf(brAddr, "%d.%d.%d.%d", option[18], option[19], option[20], option[21]);
@@ -0,0 +1,50 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2016-05-18 19:15:10.928448048 +0800
+++ udhcp-0.9.8/dhcpc.c 2016-05-18 19:48:30.724446715 +0800
@@ -117,22 +117,30 @@
}
int daemon_init(void) {
-
- pid_t pid;
-
- if((pid = fork()) < 0)
- return(-1);
- else if(pid != 0)
- exit(0); /* parent exit */
-
- /* child continues */
- dup2(2,1); /* redirect stdout to stderr because close stdout make CPU usage raise abnormally */
- close(2);
-
- setsid();
+ pid_t pid;
+
+ if((pid = fork()) < 0)
+ return(-1);
+ else if(pid != 0)
+ exit(0); /* parent exit */
+
+ /* child continues */
+ dup2(STDERR_FILENO,STDOUT_FILENO); /* redirect stdout to stderr because close stdout make CPU usage raise abnormally */
+
+ setsid();
chdir("/"); /* change working directory */
-
- return(0);
+
+ if( fd >= 0 ){
+ int fdnull;
+ fdnull = open("/dev/null", O_RDWR, 0);
+ if (fdnull != -1){
+ dup2 (fdnull, STDERR_FILENO);
+ if (fdnull > 2)
+ close (fdnull);
+ }
+ umask (0);
+ }
+ return(0);
}
#ifndef BB_VER
@@ -0,0 +1,16 @@
diff -Naur udhcp-0.9.8.orig/dhcpc.c udhcp-0.9.8/dhcpc.c
--- udhcp-0.9.8.orig/dhcpc.c 2016-06-24 13:23:31.526592500 +0800
+++ udhcp-0.9.8/dhcpc.c 2016-06-24 13:18:09.208829100 +0800
@@ -521,7 +521,11 @@
timeout = now + ((packet_num == 2) ? 4 : 2);
packet_num++;
} else {
- if (client_config.background_if_no_lease) {
+ if (client_config.background_if_no_lease
+#if 1 // ZyXEL IWei 20160623, fix kernel memory leak (in ps Slab value), do not need fork to background again and again.
+ && !client_config.foreground
+#endif
+ ) {
LOG(LOG_INFO, "No lease, forking to background.");
background();
} else if (client_config.abort_if_no_lease) {
@@ -0,0 +1,79 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2016-10-21 09:59:17.464867006 +0800
+++ udhcp-0.9.8/Makefile 2016-10-21 10:15:48.946249517 +0800
@@ -67,6 +67,15 @@
STRIP=$(CROSS_COMPILE)strip
endif
+ifeq ("$(strip ${ZCFG_PLATFORM})","BROADCOM")
+CFLAGS += -DBROADCOM_PLATFORM
+else ifeq ("$(strip ${ZCFG_PLATFORM})","ECONET")
+CFLAGS += -DECONET_PLATFORM
+endif
+ifeq ($(strip $(CONFIG_XPON_SUPPORT)),)
+CFLAGS += -DSUPPORT_XPON
+endif
+
#Sunrise customization
ifneq ($(strip $(SUNRISE_DHCP_FORCE_RENEW)),)
CFLAGS += -DSUNRISE_DHCP_FORCE_RENEW
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2016-10-21 09:59:17.604937006 +0800
+++ udhcp-0.9.8/script.c 2016-10-21 10:01:16.489460625 +0800
@@ -61,13 +61,14 @@
zcfgRet_t dhcpMsgSend(int msg_type, zcfgEid_t dstEid, int payloadLen, const char *payload)
{
- zcfgRet_t ret;
+ zcfgRet_t ret = ZCFG_SUCCESS - 1;
void *sendBuf = NULL;
void *recvBuf = NULL;
zcfgMsg_t *sendMsgHdr = NULL;
char *recv_str = NULL;
int buf_size = 0;
-
+ int retryCnt = 0;
+
buf_size = sizeof(zcfgMsg_t)+payloadLen;
sendBuf = malloc(buf_size);
sendMsgHdr = (zcfgMsg_t*)sendBuf;
@@ -77,18 +78,34 @@
sendMsgHdr->srcEid = ZCFG_EID_UDHCPC;
sendMsgHdr->dstEid = dstEid;
- LOG(LOG_INFO, "%s: msgType[%d]\n", __FUNCTION__, msg_type);
-
if(payload != NULL)
memcpy(sendBuf+sizeof(zcfgMsg_t), payload, payloadLen);
+#if defined(ECONET_PLATFORM) && defined(SUPPORT_XPON)
+ while ((ret < ZCFG_SUCCESS) && (retryCnt <= 3)) {
+ LOG(LOG_INFO, "udhcp send message to ESMD: msgType[%d] (retry=%d)", msg_type^ZCFG_NO_WAIT_REPLY, retryCnt);
+ ret = zcfgMsgSendAndGetReply(sendMsgHdr, (zcfgMsg_t **)&recvBuf, 0);
+ if (ret >= ZCFG_SUCCESS) {
+ if (recvBuf) {
+ recv_str = (char *)recvBuf+sizeof(zcfgMsg_t);
+ printf("Receive message : %s\n", recv_str);
+ free(recvBuf);
+ }
+ break;
+ } else {
+ retryCnt++;
+ usleep(100);
+ }
+ }
+#else
+ LOG(LOG_INFO, "%s: msgType[%d]", __FUNCTION__, msg_type);
ret = zcfgMsgSendAndGetReply(sendMsgHdr, (zcfgMsg_t **)&recvBuf, 0);
-
if(ret == ZCFG_SUCCESS) {
recv_str = (char *)recvBuf+sizeof(zcfgMsg_t);
printf("Receive message : %s\n", recv_str);
free(recvBuf);
}
+#endif
return ret;
}
@@ -0,0 +1,194 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2016-12-05 16:08:19.814733302 +0800
+++ udhcp-0.9.8/dhcpc.c 2016-12-05 16:08:19.834723303 +0800
@@ -90,7 +90,12 @@
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
char Forecerenewkey[128]="";
#endif
+
+#if defined(ECONET_PLATFORM) && !defined(SUPPORT_XPON) //only for en7512 projects
+#define INIT_TIMEOUT 60 //original source code definition
+#else
#define INIT_TIMEOUT 5
+#endif
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
Index: udhcp-0.9.8/clientpacket.c
===================================================================
--- udhcp-0.9.8.orig/clientpacket.c 2016-12-05 16:08:19.654813301 +0800
+++ udhcp-0.9.8/clientpacket.c 2016-12-05 16:08:19.834723303 +0800
@@ -187,7 +187,76 @@
return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT, inf);
}
+#if defined(ECONET_PLATFORM) && !defined(SUPPORT_XPON) //only for en7512 projects
+#include <netinet/ether.h>
+/* return -1 on errors that are fatal for the socket, -2 for those that aren't */
+int get_raw_packet(struct dhcpMessage *payload, int fd)
+{
+ int bytes;
+ //struct udp_dhcp_packet packet;
+ char buffer[(sizeof(struct ether_header)+sizeof(struct udp_dhcp_packet))];
+ struct udp_dhcp_packet *packet;
+ u_int32_t source, dest;
+ u_int16_t check;
+
+ memset(buffer, 0, sizeof(buffer));
+ bytes = read(fd, buffer, sizeof(buffer));
+ if (bytes < 0) {
+ DEBUG(LOG_INFO, "couldn't read on raw listening socket -- ignoring");
+ usleep(500000); /* possible down interface, looping condition */
+ return -1;
+ }
+ if (bytes < (int) (sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct udphdr))) {
+ DEBUG(LOG_INFO, "message too short, ignoring");
+ return -2;
+ }
+
+ packet = (struct udp_dhcp_packet *)(buffer + sizeof(struct ether_header));
+ if (bytes < ntohs(packet->ip.tot_len)) {
+ DEBUG(LOG_INFO, "Truncated packet");
+ return -2;
+ }
+ /* ignore any extra garbage bytes */
+ bytes = ntohs(packet->ip.tot_len);
+ /* Make sure its the right packet for us, and that it passes sanity checks */
+ if (packet->ip.protocol != IPPROTO_UDP || packet->ip.version != IPVERSION ||
+ packet->ip.ihl != sizeof(packet->ip) >> 2 || packet->udp.dest != htons(CLIENT_PORT) ||
+ bytes > (int) sizeof(struct udp_dhcp_packet) ||
+ ntohs(packet->udp.len) != (short) (bytes - sizeof(packet->ip))) {
+ DEBUG(LOG_INFO, "unrelated/bogus packet");
+ return -2;
+ }
+ /* check IP checksum */
+ check = packet->ip.check;
+ packet->ip.check = 0;
+ if (check != checksum(&(packet->ip), sizeof(packet->ip))) {
+ DEBUG(LOG_INFO, "bad IP header checksum, ignoring");
+ return -1;
+ }
+ /* verify the UDP checksum by replacing the header with a psuedo header */
+ source = packet->ip.saddr;
+ dest = packet->ip.daddr;
+ check = packet->udp.check;
+ packet->udp.check = 0;
+ memset(&packet->ip, 0, sizeof(packet->ip));
+ packet->ip.protocol = IPPROTO_UDP;
+ packet->ip.saddr = source;
+ packet->ip.daddr = dest;
+ packet->ip.tot_len = packet->udp.len; /* cheat on the psuedo-header */
+ if (check && check != checksum(packet, bytes)) {
+ DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring");
+ return -2;
+ }
+ memcpy(payload, &(packet->data), bytes - (sizeof(packet->ip) + sizeof(packet->udp)));
+ if (ntohl(payload->cookie) != DHCP_MAGIC) {
+ LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring");
+ return -2;
+ }
+ DEBUG(LOG_INFO, "oooooh!!! got some!");
+ return bytes - (sizeof(packet->ip) + sizeof(packet->udp));
+}
+#else
/* return -1 on errors that are fatal for the socket, -2 for those that aren't */
int get_raw_packet(struct dhcpMessage *payload, int fd)
{
@@ -258,6 +327,6 @@
}
DEBUG(LOG_INFO, "oooooh!!! got some!");
return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
-
}
+#endif
Index: udhcp-0.9.8/socket.c
===================================================================
--- udhcp-0.9.8.orig/socket.c 2002-09-21 04:36:15.000000000 +0800
+++ udhcp-0.9.8/socket.c 2016-12-05 16:08:19.834723303 +0800
@@ -131,7 +131,64 @@
return fd;
}
+#if defined(ECONET_PLATFORM) && !defined(SUPPORT_XPON) //only for en7512 projects
+#include <linux/filter.h>
+int raw_socket(int ifindex)
+{
+ int fd;
+ struct sockaddr_ll sock;
+ struct sock_fprog filter;
+ /*
+ "tcpdump -dd udp dst port 68"
+ "-dd: Dump packet-matching code as a C program fragment."
+ */
+ struct sock_filter ft[] = {
+ { 0x28, 0, 0, 0x0000000c },
+ { 0x15, 0, 4, 0x000086dd },
+ { 0x30, 0, 0, 0x00000014 },
+ { 0x15, 0, 11, 0x00000011 },
+ { 0x28, 0, 0, 0x00000038 },
+ { 0x15, 8, 9, 0x00000044 },
+ { 0x15, 0, 8, 0x00000800 },
+ { 0x30, 0, 0, 0x00000017 },
+ { 0x15, 0, 6, 0x00000011 },
+ { 0x28, 0, 0, 0x00000014 },
+ { 0x45, 4, 0, 0x00001fff },
+ { 0xb1, 0, 0, 0x0000000e },
+ { 0x48, 0, 0, 0x00000010 },
+ { 0x15, 0, 1, 0x00000044 },
+ { 0x6, 0, 0, 0x0000ffff },
+ { 0x6, 0, 0, 0x00000000 }
+ };
+ int i, lineCount;
+ DEBUG(LOG_INFO, "Opening raw socket on ifindex %d\n", ifindex);
+ if ((fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP))) < 0) {
+ DEBUG(LOG_ERR, "socket call failed: %s", strerror(errno));
+ return -1;
+ }
+
+ sock.sll_family = AF_PACKET;
+ sock.sll_protocol = htons(ETH_P_IP);
+ sock.sll_ifindex = ifindex;
+ if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
+ DEBUG(LOG_ERR, "bind call failed: %s", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ filter.filter = ft;
+ filter.len = 16;
+ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)) < 0 )
+ {
+ perror("Cannot attach filter");
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+#else
int raw_socket(int ifindex)
{
int fd;
@@ -154,4 +211,4 @@
return fd;
}
-
+#endif
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2016-12-05 16:08:19.826727303 +0800
+++ udhcp-0.9.8/Makefile 2016-12-05 16:08:52.629981563 +0800
@@ -72,7 +72,7 @@
else ifeq ("$(strip ${ZCFG_PLATFORM})","ECONET")
CFLAGS += -DECONET_PLATFORM
endif
-ifeq ($(strip $(CONFIG_XPON_SUPPORT)),)
+ifneq ($(strip $(CONFIG_XPON_SUPPORT)),)
CFLAGS += -DSUPPORT_XPON
endif
@@ -0,0 +1,87 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2017-04-13 14:35:22.153310901 +0800
+++ udhcp-0.9.8/dhcpc.c 2017-04-13 14:36:29.026159927 +0800
@@ -329,6 +329,7 @@
time_t now;
int max_fd;
int sig;
+ int vlanHuntEnable = 0;
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
char renewkey[128] = {0};
@@ -435,6 +436,7 @@
#if 1 /* vlan autohunt, ZyXEL, John */
case 'V':
vlanId = atoi(optarg);
+ vlanHuntEnable = 1;
break;
#endif
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
@@ -458,7 +460,7 @@
exit_client(1);
#if 1 /* ZyXEL DHCP options support, ZyXEL, John */
- read_config_options(client_config.interface);
+ read_config_options(client_config.interface, vlanHuntEnable);
#else
if (!client_config.clientid) {
client_config.clientid = xmalloc(6 + 3);
@@ -667,7 +669,7 @@
if (*message == DHCPOFFER) {
#ifdef SUNRISE_VLANHUNT_CUSTOMIZATION
temp = get_option(&packet, 0x2b);
- if(vlanId != -1){
+ if(vlanHuntEnable){
if (temp != NULL)
dhcpMsgSend(ZCFG_MSG_VLAN_HUNT_SUCCESS, ZCFG_EID_VLAN_AUTOHUNT, 0, NULL);
else
@@ -738,7 +740,7 @@
requested_ip = packet.yiaddr;
#if 1 /* vlan autohunt, ZyXEL, John */
#ifndef SUNRISE_VLANHUNT_CUSTOMIZATION
- if(vlanId != -1){
+ if(vlanHuntEnable){
dhcpMsgSend(ZCFG_MSG_VLAN_HUNT_SUCCESS, ZCFG_EID_VLAN_AUTOHUNT, 0, NULL);
exit_client(0);
}
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2017-04-13 14:35:22.073310901 +0800
+++ udhcp-0.9.8/options.c 2017-04-13 14:35:22.169310902 +0800
@@ -285,7 +285,7 @@
}
}
-int read_config_options(const char* intfName)
+int read_config_options(const char* intfName, int IsVlanHuntEnable)
{
rdm_Dhcpv4ReqOpt_t *reqOptObj = NULL;
rdm_Dhcpv4SentOpt_t *sentOptObj = NULL;
@@ -326,8 +326,12 @@
free(dhcpcObj);
}
- if (found == 0)
+ if (found == 0){
+ if(IsVlanHuntEnable){
+ sent_config_options[0] = DHCP_END;
+ }
return 0;
+ }
IID_INIT(optIid);
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2017-04-13 14:35:22.073310901 +0800
+++ udhcp-0.9.8/options.h 2017-04-13 14:35:22.169310902 +0800
@@ -68,7 +68,7 @@
#if 1 /* ZyXEL DHCP option support (porting from BRCM and MSTC), John */
void hexOptionToString(char *hexOpt, char *hexStr);
void hexStringToOption(char * hexStr,char * hexOpt);
-int read_config_options(const char* intfName);
+int read_config_options(const char* intfName, int IsVlanHuntEnable);
int find_dhcp_options(char code);
#endif
@@ -0,0 +1,13 @@
Index: udhcp-0.9.8/debug.h
===================================================================
--- udhcp-0.9.8.orig/debug.h 2002-09-21 04:36:15.000000000 +0800
+++ udhcp-0.9.8/debug.h 2018-05-09 10:35:11.082418630 +0800
@@ -13,7 +13,7 @@
# define LOG(level, str, args...) do { printf(str, ## args); \
printf("\n"); \
syslog(level, str, ## args); } while(0)
-# define OPEN_LOG(name) openlog(name, 0, 0)
+# define OPEN_LOG(name) openlog(name, LOG_PID, 0)
#define CLOSE_LOG() closelog()
#else
# define LOG_EMERG "EMERGENCY!"
@@ -0,0 +1,13 @@
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2018-09-06 14:54:09.841179068 +0800
+++ udhcp-0.9.8/script.c 2018-09-06 14:55:39.420382671 +0800
@@ -308,7 +308,7 @@
int num_options = 0;
int i, j;
//char **envp;
- char buf[128] = {0};
+ char buf[256] = {0};
char ip[16] = {0};
unsigned char *tmpIp;
unsigned char *temp;
@@ -0,0 +1,124 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2018-11-15 10:25:57.566725999 +0800
+++ udhcp-0.9.8/dhcpc.c 2018-11-15 10:39:41.666812491 +0800
@@ -343,6 +343,10 @@
int isNew = FALSE;
#endif
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+int discoverSet = 0;
+#endif
+
static struct option arg_options[] = {
#if 0 /* ZyXEL DHCP options support, ZyXEL, John */
{"clientid", required_argument, 0, 'c'},
@@ -510,6 +514,13 @@
/* timeout dropped to zero */
switch (state) {
case INIT_SELECTING:
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+ if(discoverSet >= 2){
+ timeout = 0x7fffffff;
+ run_script(NULL, "fakeIP");
+ continue;
+ }
+#endif
if (packet_num < 3) {
if (packet_num == 0)
xid = random_xid();
@@ -542,6 +553,9 @@
/* wait to try again */
packet_num = 0;
timeout = now + INIT_TIMEOUT;
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+ discoverSet++;
+#endif
}
break;
case RENEW_REQUESTED:
@@ -750,6 +764,9 @@
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
state = BOUND;
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+ discoverSet = 0;
+#endif
#ifdef SUNRISE_DHCP_FORCE_RENEW //DHCP Force Renew
change_mode(LISTEN_KERNEL);
#else
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2018-11-15 10:25:57.534725840 +0800
+++ udhcp-0.9.8/script.c 2018-11-15 10:40:14.614975872 +0800
@@ -29,6 +29,9 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+#include <time.h>
+#endif
#include "options.h"
#include "dhcpd.h"
@@ -415,6 +418,33 @@
return NULL;
}
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+static char **fill_envp_fakeIP(void)
+{
+ struct json_object *dhcpc_opt = NULL;
+ const char *payload = NULL;
+ int payloadLen = 0;
+ char ip[16] = {0};
+
+ dhcpc_opt = json_object_new_object();
+
+ srand(time(NULL));
+ sprintf(ip, "169.254.%d.%d", rand() % 256, rand() % 254 + 1);
+ json_object_object_add(dhcpc_opt, "ip", json_object_new_string(ip));
+ json_object_object_add(dhcpc_opt, "subnet", json_object_new_string("255.255.0.0"));
+ json_object_object_add(dhcpc_opt, "addressAssigned", json_object_new_boolean(true));
+ json_object_object_add(dhcpc_opt, "pidfile", json_object_new_string(client_config.pidfile));
+
+ payload = json_object_to_json_string(dhcpc_opt);
+ payloadLen = strlen(payload) + 1;
+
+ dhcpMsgSend(ZCFG_MSG_DHCPC_BOUND, ZCFG_EID_ESMD, payloadLen, payload);
+
+ json_object_put(dhcpc_opt);
+
+ return NULL;
+}
+#endif
/* Call a script with a par file and env vars */
void run_script(struct dhcpMessage *packet, const char *name)
@@ -439,6 +469,11 @@
free(envp);
#endif
}
+#ifdef ZYXEL_FAKE_IP_169_254_X_X
+ else if (strcmp(name, "fakeIP") == 0) {
+ fill_envp_fakeIP();
+ }
+#endif
else if (strcmp(name, "deconfig") == 0) {
/* Expired, set the connection down */
printf("Expired, set the connection down\n");
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2018-11-15 10:25:57.550725920 +0800
+++ udhcp-0.9.8/Makefile 2018-11-15 10:38:42.586519527 +0800
@@ -76,6 +76,10 @@
CFLAGS += -DSUPPORT_XPON
endif
+ifneq ($(strip $(CONFIG_ZYXEL_FAKE_IP_169_254_X_X)),)
+CFLAGS += -DZYXEL_FAKE_IP_169_254_X_X
+endif
+
#Sunrise customization
ifneq ($(strip $(SUNRISE_DHCP_FORCE_RENEW)),)
CFLAGS += -DSUNRISE_DHCP_FORCE_RENEW
@@ -0,0 +1,16 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2019-01-14 13:43:52.826583349 +0800
+++ udhcp-0.9.8/dhcpc.c 2019-01-14 13:47:01.229364410 +0800
@@ -91,11 +91,7 @@
char Forecerenewkey[128]="";
#endif
-#if defined(ECONET_PLATFORM) && !defined(SUPPORT_XPON) //only for en7512 projects
-#define INIT_TIMEOUT 60 //original source code definition
-#else
#define INIT_TIMEOUT 5
-#endif
#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
@@ -0,0 +1,184 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2019-03-27 15:44:24.374141378 +0800
+++ udhcp-0.9.8/Makefile 2019-03-27 17:01:31.198268860 +0800
@@ -28,7 +28,7 @@
#INC_PATH = -I$(USERSPACE_ZCFG_INCLUDE)
-LINK_LIBS = -ljson -lzcfg_msg -lzcmd_tool -lzcfg_fe_rdm_access -lzcfg_fe_rdm_struct
+LINK_LIBS = -ljson -lzcfg_msg -lzcmd_tool -lzcfg_fe_rdm_access -lzcfg_fe_rdm_struct -lm
OBJS_SHARED = options.o socket.o packet.o pidfile.o
DHCPD_OBJS = dhcpd.o arpping.o files.o leases.o serverpacket.o
@@ -76,6 +76,10 @@
CFLAGS += -DSUPPORT_XPON
endif
+ifneq ($(strip $(CONFIG_ZYXEL_DHCP_DISCOVER_EXPONENTIAL)),)
+CFLAGS += -DZYXEL_DHCP_DISCOVER_EXPONENTIAL
+endif
+
ifneq ($(strip $(CONFIG_ZYXEL_FAKE_IP_169_254_X_X)),)
CFLAGS += -DZYXEL_FAKE_IP_169_254_X_X
endif
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2019-03-27 15:44:24.382141378 +0800
+++ udhcp-0.9.8/dhcpc.c 2019-03-27 17:42:40.826336905 +0800
@@ -305,6 +305,95 @@
}
+#ifdef ZYXEL_DHCP_DISCOVER_EXPONENTIAL
+/*!
+ * for RFC2131 exponential backoff algorithm,
+ * caculate the vaule of exponential
+ *
+ * @param[in] retrytimes message retransmission times
+ *
+ * @return the vaule of exponential
+*/
+static int resultExponentialBackoff(int retrytimes)
+{
+ int valueExponential = 0;
+ valueExponential = pow(2,retrytimes );
+ return valueExponential;
+}
+
+static void dhcp_discover_exponential(unsigned long *xid, time_t *now){
+ if ( resultExponentialBackoff(packet_num) <= 64 ) {
+ if (packet_num == 0)
+ *xid = random_xid();
+#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
+ int j;
+ *xid = *xid / 1000000;
+ for(j = 4; j < 6; j++ ){
+ *xid = *xid * 1000 + (unsigned int)client_config.arp[j];
+ }
+#endif
+ /* send discover packet */
+ send_discover(*xid , requested_ip); /* broadcast */
+
+ if(resultExponentialBackoff(packet_num)<=64){
+ timeout = *now + resultExponentialBackoff(packet_num);
+ }else{
+ timeout = *now;
+ }
+ packet_num++;
+ } else {
+ if (client_config.background_if_no_lease
+#if 1 // ZyXEL IWei 20160623, fix kernel memory leak (in ps Slab value), do not need fork to background again and again.
+ && !client_config.foreground
+#endif
+ ) {
+ LOG(LOG_INFO, "No lease, forking to background.");
+ background();
+ } else if (client_config.abort_if_no_lease) {
+ LOG(LOG_INFO, "No lease, failing.");
+ exit_client(1);
+ }
+ /* wait to try again */
+ timeout = *now;
+ packet_num = 0;
+ }
+}
+#else
+static void dhcp_discover_general(unsigned long *xid, time_t *now){
+ if (packet_num < 3) {
+ if (packet_num == 0)
+ *xid = random_xid();
+
+#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
+ int j;
+ *xid = *xid / 1000000;
+ for(j = 4; j < 6; j++ ){
+ *xid = *xid * 1000 + (unsigned int)client_config.arp[j];
+ }
+#endif
+ /* send discover packet */
+ send_discover(*xid, requested_ip); /* broadcast */
+
+ timeout = *now + ((packet_num == 2) ? 4 : 2);
+ packet_num++;
+ } else {
+ if (client_config.background_if_no_lease
+#if 1 // ZyXEL IWei 20160623, fix kernel memory leak (in ps Slab value), do not need fork to background again and again.
+ && !client_config.foreground
+#endif
+ ) {
+ LOG(LOG_INFO, "No lease, forking to background.");
+ background();
+ } else if (client_config.abort_if_no_lease) {
+ LOG(LOG_INFO, "No lease, failing.");
+ exit_client(1);
+ }
+ /* wait to try again */
+ packet_num = 0;
+ timeout = *now + INIT_TIMEOUT;
+ }
+}
+#endif
#ifdef COMBINED_BINARY
int udhcpc_main(int argc, char *argv[])
@@ -510,49 +599,21 @@
/* timeout dropped to zero */
switch (state) {
case INIT_SELECTING:
+#ifdef ZYXEL_DHCP_DISCOVER_EXPONENTIAL
+ dhcp_discover_exponential(&xid, &now);
+#else
#ifdef ZYXEL_FAKE_IP_169_254_X_X
- if(discoverSet >= 2){
- timeout = 0x7fffffff;
- run_script(NULL, "fakeIP");
- continue;
- }
-#endif
- if (packet_num < 3) {
- if (packet_num == 0)
- xid = random_xid();
-
-#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
- int j;
- xid = xid / 1000000;
- for(j = 4; j < 6; j++ ){
- xid = xid * 1000 + (unsigned int)client_config.arp[j];
+ if(discoverSet >= 2){
+ timeout = 0x7fffffff;
+ run_script(NULL, "fakeIP");
+ continue;
}
#endif
-
- /* send discover packet */
- send_discover(xid, requested_ip); /* broadcast */
-
- timeout = now + ((packet_num == 2) ? 4 : 2);
- packet_num++;
- } else {
- if (client_config.background_if_no_lease
-#if 1 // ZyXEL IWei 20160623, fix kernel memory leak (in ps Slab value), do not need fork to background again and again.
- && !client_config.foreground
-#endif
- ) {
- LOG(LOG_INFO, "No lease, forking to background.");
- background();
- } else if (client_config.abort_if_no_lease) {
- LOG(LOG_INFO, "No lease, failing.");
- exit_client(1);
- }
- /* wait to try again */
- packet_num = 0;
- timeout = now + INIT_TIMEOUT;
+ dhcp_discover_general(&xid, &now);
#ifdef ZYXEL_FAKE_IP_169_254_X_X
- discoverSet++;
+ discoverSet++;
#endif
- }
+#endif //ZYXEL_DHCP_DISCOVER_EXPONENTIAL
break;
case RENEW_REQUESTED:
case REQUESTING:
@@ -0,0 +1,24 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2019-09-04 16:25:53.665973572 +0800
+++ udhcp-0.9.8/Makefile 2019-09-04 16:26:18.361078732 +0800
@@ -14,8 +14,8 @@
#DEBUG=1
# Uncomment this to output messages to syslog, otherwise, messages go to stdout
-CFLAGS += -DSYSLOG
-
+CFLAGS += -DSYSLOG -I$(STAGING_DIR)/usr/include
+LDFLAGS += -L$(STAGING_DIR)/usr/lib
#CROSS_COMPILE=arm-uclibc-
#CC = $(CROSS_COMPILE)gcc
#LD = $(CROSS_COMPILE)gcc
@@ -28,7 +28,7 @@
#INC_PATH = -I$(USERSPACE_ZCFG_INCLUDE)
-LINK_LIBS = -ljson -lzcfg_msg -lzcmd_tool -lzcfg_fe_rdm_access -lzcfg_fe_rdm_struct -lm
+LINK_LIBS = -ljson -lzcfg_msg -lzcmd_tool -lzcfg_fe_rdm_access -lzcfg_fe_rdm_struct -lm -lzlog -lzos
OBJS_SHARED = options.o socket.o packet.o pidfile.o
DHCPD_OBJS = dhcpd.o arpping.o files.o leases.o serverpacket.o
@@ -0,0 +1,254 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2020-09-02 11:08:31.680684938 +0800
+++ udhcp-0.9.8/Makefile 2020-09-02 16:38:02.486980296 +0800
@@ -98,6 +98,10 @@
CFLAGS += -DSUNRISE_VLANHUNT_CUSTOMIZATION
endif
+ifneq ($(strip $(CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG)),)
+CFLAGS += -DCONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+endif
+
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/clientpacket.c
===================================================================
--- udhcp-0.9.8.orig/clientpacket.c 2020-09-02 11:08:31.672684939 +0800
+++ udhcp-0.9.8/clientpacket.c 2020-09-02 16:36:56.930851111 +0800
@@ -126,6 +126,10 @@
add_requests(&packet);
LOG(LOG_DEBUG, "Sending discover...");
+ #ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ if(ttchecklogInif(client_config.interface))
+ TTDHCPLOG(LOG_DEBUG, "DHCP_Client: DHCPDISCOVERY src mac=%02x:%02x:%02x:%02x:%02x:%02x dst mac=ff:ff:ff:ff:ff:ff src ip=0.0.0.0 dst ip=255.255.255.255",client_config.arp[0], client_config.arp[1], client_config.arp[2],client_config.arp[3], client_config.arp[4], client_config.arp[5]);
+ #endif
return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
Index: udhcp-0.9.8/debug.h
===================================================================
--- udhcp-0.9.8.orig/debug.h 2020-09-02 11:08:31.672684939 +0800
+++ udhcp-0.9.8/debug.h 2020-09-02 16:37:09.380979057 +0800
@@ -13,6 +13,9 @@
# define LOG(level, str, args...) do { printf(str, ## args); \
printf("\n"); \
syslog(level, str, ## args); } while(0)
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+# define TTDHCPLOG(level, str, args...) syslog(level, str, ## args)
+#endif
# define OPEN_LOG(name) openlog(name, LOG_PID, 0)
#define CLOSE_LOG() closelog()
#else
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2020-09-02 11:08:31.680684938 +0800
+++ udhcp-0.9.8/dhcpc.c 2020-09-02 16:37:47.183720690 +0800
@@ -50,6 +50,11 @@
#include "zcfg_common.h"
#include "zcfg_fe_rdm_access.h"
#include "zcfg_msg.h"
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+#include "zcfg_rdm_obj.h"
+#include "zcfg_rdm_oid.h"
+#include "zcfg_fe_rdm_struct.h"
+#endif
#if 1 //__ZyXEL__,20150331,Cj_Lai Transation ID + last four words of WAN interface MAC address.
#include <math.h>
@@ -144,6 +149,96 @@
return(0);
}
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+int ttchecklogInif(char* intfName)
+{
+ rdm_IpIface_t *ipIface = NULL;
+ objIndex_t ipIfaceIid;
+ int dhcplogflag = 0;
+
+ /*find tt iptv interface via tt interface name*/
+ IID_INIT(ipIfaceIid);
+ while(zcfgFeObjStructGetNextWithoutUpdate(RDM_OID_IP_IFACE, &ipIfaceIid, (void **)&ipIface) == ZCFG_SUCCESS) {
+ if ( !strcmp(ipIface->X_ZYXEL_IfName, intfName) && strstr(ipIface->X_TT_SrvName,"IPTV") ){
+ dhcplogflag = 1;
+ free(ipIface);
+ break;
+ }
+ free(ipIface);
+ }
+
+ return dhcplogflag;
+}
+
+void setStatus(int status)
+{
+ static int wasAssigned=0;
+
+ if (status == 1)
+ {
+ wasAssigned = 1;
+ /*
+ * We don't have to send out a DHCPC_STATUS_CHANGED msg here.
+ * We did that from run_script.
+ */
+ }
+ else
+ {
+ /*
+ * We went from assigned to un-assigned, send a DHCPC_STATUS_CHANGED
+ * msg.
+ */
+ if (wasAssigned == 1)
+ {
+ if(state != RELEASED)
+ {
+ //NACK
+ struct in_addr temp_addr={0};
+ struct in_addr temp2_addr={0};
+ char message_log[128];
+ int log_len = 0;
+ FILE *fp;
+ char fileIP[512];
+ char file_row[2][32];
+
+ temp_addr.s_addr = server_addr;
+ temp2_addr.s_addr = requested_ip;
+ if((fp = fopen("/var/dhcp_server", "r")) != NULL){
+ while (fgets(fileIP, sizeof(fileIP), fp))
+ {
+ sscanf(fileIP, "%s %s", file_row[0], file_row[1]);
+ if(strcmp(file_row[0], inet_ntoa(temp_addr))==0)
+ {
+ log_len += sprintf(message_log, "DHCP_Client: DHCPNACK src mac=%s dst mac=%02x:%02x:%02x:%02x:%02x:%02x src ip=%s", file_row[1],
+ client_config.arp[0], client_config.arp[1], client_config.arp[2],client_config.arp[3], client_config.arp[4], client_config.arp[5], inet_ntoa(temp_addr));
+ log_len += sprintf(message_log+log_len, "dst ip=%s ", inet_ntoa(temp2_addr));
+ sprintf(message_log+log_len, "assigned ip=%s", inet_ntoa(temp2_addr));
+ if(ttchecklogInif(client_config.interface))
+ TTDHCPLOG(LOG_DEBUG, message_log);
+ break;
+ }
+ }
+ fclose(fp);
+ system("rm /var/dhcp_server \n");
+ }
+ else
+ {
+ log_len += sprintf(message_log, "DHCP_Client: DHCPNACK src mac=ff:ff:ff:ff:ff:ff dst mac=%02x:%02x:%02x:%02x:%02x:%02x src ip=%s",
+ client_config.arp[0], client_config.arp[1], client_config.arp[2],client_config.arp[3], client_config.arp[4], client_config.arp[5], inet_ntoa(temp_addr));
+ log_len += sprintf(message_log+log_len, "dst ip=%s ", inet_ntoa(temp2_addr));
+ sprintf(message_log+log_len, "assigned ip=%s", inet_ntoa(temp2_addr));
+ if(ttchecklogInif(client_config.interface))
+ TTDHCPLOG(LOG_DEBUG, message_log);
+ }
+ }
+ wasAssigned = 0;
+ }
+ }
+
+ return;
+}
+#endif
+
#ifndef BB_VER
static void show_usage(void)
{
@@ -254,6 +349,46 @@
json_object_put(dhcpc_opt);
}
#endif
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ //RELEASE
+ struct in_addr requested_addr={0};
+ struct in_addr tmp_addr={0};
+ char message_log[128];
+ int log_len = 0;
+ requested_addr.s_addr = requested_ip;
+ tmp_addr.s_addr = server_addr;
+ FILE *fp;
+ char fileIP[512];
+ char file_row[2][32];
+
+ if((fp = fopen("/var/dhcp_server", "r")) != NULL){
+ while (fgets(fileIP, sizeof(fileIP), fp))
+ {
+ sscanf(fileIP, "%s %s", file_row[0], file_row[1]);
+ if(strcmp(file_row[0], inet_ntoa(tmp_addr))==0)
+ {
+ log_len += sprintf(message_log, "DHCP_Client: DHCPRELEASE src mac=%02x:%02x:%02x:%02x:%02x:%02x dst mac=%s src ip=%s ", client_config.arp[0], client_config.arp[1],
+ client_config.arp[2],client_config.arp[3], client_config.arp[4], client_config.arp[5], file_row[1], inet_ntoa(requested_addr));
+ log_len += sprintf(message_log+log_len, "dst ip=%s ", inet_ntoa(tmp_addr));
+ sprintf(message_log+log_len, "requested ip=%s", inet_ntoa(requested_addr));
+ if(ttchecklogInif(client_config.interface))
+ TTDHCPLOG(LOG_DEBUG, message_log);
+ break;
+ }
+ }
+ fclose(fp);
+ system("rm /var/dhcp_server \n");
+ }
+ else
+ {
+ log_len += sprintf(message_log, "DHCP_Client: DHCPRELEASE src mac=%02x:%02x:%02x:%02x:%02x:%02x dst mac=ff:ff:ff:ff:ff:ff src ip=%s ", client_config.arp[0], client_config.arp[1],
+ client_config.arp[2],client_config.arp[3], client_config.arp[4], client_config.arp[5], inet_ntoa(requested_addr));
+ log_len += sprintf(message_log+log_len, "dst ip=%s ", inet_ntoa(tmp_addr));
+ sprintf(message_log+log_len, "requested ip=%s", inet_ntoa(requested_addr));
+ if(ttchecklogInif(client_config.interface))
+ TTDHCPLOG(LOG_DEBUG, message_log);
+ }
+#endif
send_release(server_addr, requested_ip, client_config.interface); /* unicast */
run_script(NULL, "deconfig");
@@ -262,6 +397,9 @@
change_mode(LISTEN_NONE);
state = RELEASED;
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ setStatus(0);
+#endif
timeout = 0x7fffffff;
}
@@ -566,6 +704,9 @@
signal(SIGTERM, signal_handler);
state = INIT_SELECTING;
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ setStatus(0);
+#endif
run_script(NULL, "deconfig");
change_mode(LISTEN_RAW);
@@ -599,6 +740,9 @@
/* timeout dropped to zero */
switch (state) {
case INIT_SELECTING:
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ setStatus(0);
+#endif
#ifdef ZYXEL_DHCP_DISCOVER_EXPONENTIAL
dhcp_discover_exponential(&xid, &now);
#else
@@ -821,6 +965,9 @@
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
state = BOUND;
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ setStatus(1);
+#endif
#ifdef ZYXEL_FAKE_IP_169_254_X_X
discoverSet = 0;
#endif
@@ -866,6 +1013,9 @@
#endif
state = INIT_SELECTING;
+#ifdef CONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
+ setStatus(0);
+#endif
timeout = now;
requested_ip = 0;
packet_num = 0;
@@ -0,0 +1,13 @@
Index: udhcp-0.9.8/script.c
===================================================================
--- udhcp-0.9.8.orig/script.c 2020-03-20 14:29:10.180616346 +0800
+++ udhcp-0.9.8/script.c 2020-03-20 14:30:56.958366858 +0800
@@ -207,7 +207,7 @@
case OPTION_STRING:
#if 1 /* ZyXEL DHCP option support (porting from BRCM and MSTC), John */
/* DHCP option 43 */
- if(type_p->code == 0x2b || type_p->code == 0x79){
+ if(type_p->code == 0x2b || type_p->code == 0x79 || type_p->code == 0x0f){
if(type_p->code == 0x79){
//RFC3442, if option 121 contain default route, the priority is higher than option3.
if(getDefaultRouteFromOption121((char *)(option - 2), optStr) == true)
@@ -0,0 +1,69 @@
Index: udhcp-0.9.8/Makefile
===================================================================
--- udhcp-0.9.8.orig/Makefile 2020-12-01 12:20:20.876303626 +0800
+++ udhcp-0.9.8/Makefile 2020-12-01 13:18:09.840958613 +0800
@@ -102,6 +102,10 @@
CFLAGS += -DCONFIG_ZYXEL_CUSTOMIZATION_DEVICELOG
endif
+ifneq ($(strip $(CONFIG_TT_CUSTOMIZATION_TR069)),)
+CFLAGS += -DCONFIG_TT_CUSTOMIZATION_TR069
+endif
+
all: clean $(EXEC1) $(EXEC2) $(EXEC3)
$(STRIP) --remove-section=.note --remove-section=.comment $(EXEC1) $(EXEC2) $(EXEC3)
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2020-12-01 12:20:20.860303626 +0800
+++ udhcp-0.9.8/options.c 2020-12-01 13:18:28.755205690 +0800
@@ -84,6 +84,10 @@
int last_option_index = sizeof(options)/sizeof(struct dhcp_option) - 1;
#endif
+#ifdef CONFIG_TT_CUSTOMIZATION_TR069
+u_int32_t X_TTNET_Bootp_Flag = 0;
+#endif
+
/* get an option with bounds checking (warning, not aligned). */
unsigned char *get_option(struct dhcpMessage *packet, int code)
{
@@ -305,6 +309,9 @@
while(zcfgFeObjStructGetNext(RDM_OID_IP_IFACE, &ipIfaceIid, (void **)&ipIface) == ZCFG_SUCCESS) {
if ( !strcmp(ipIface->X_ZYXEL_IfName, intfName) ){
sprintf(ipIntf, "IP.Interface.%d", ipIfaceIid.idx[0]);
+#ifdef CONFIG_TT_CUSTOMIZATION_TR069
+ X_TTNET_Bootp_Flag = ipIface->X_TTNET_Bootp_Flag;
+#endif
free(ipIface);
break;
}
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2020-12-01 12:20:20.860303626 +0800
+++ udhcp-0.9.8/options.h 2020-12-01 13:18:43.197846851 +0800
@@ -58,6 +58,9 @@
extern int optLen;
extern unsigned char sent_config_options[];
#endif
+#ifdef CONFIG_TT_CUSTOMIZATION_TR069
+extern u_int32_t X_TTNET_Bootp_Flag;
+#endif
unsigned char *get_option(struct dhcpMessage *packet, int code);
int end_option(unsigned char *optionptr);
Index: udhcp-0.9.8/packet.c
===================================================================
--- udhcp-0.9.8.orig/packet.c 2020-12-01 12:20:20.836303627 +0800
+++ udhcp-0.9.8/packet.c 2020-12-01 13:19:02.767305807 +0800
@@ -38,6 +38,10 @@
}
packet->htype = ETH_10MB;
packet->hlen = ETH_10MB_LEN;
+#ifdef CONFIG_TT_CUSTOMIZATION_TR069
+ if(X_TTNET_Bootp_Flag == 0)
+ packet->flags |= htons(BROADCAST_FLAG);
+#endif
packet->cookie = htonl(DHCP_MAGIC);
packet->options[0] = DHCP_END;
add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type);
@@ -0,0 +1,76 @@
Index: udhcp-0.9.8/dhcpc.c
===================================================================
--- udhcp-0.9.8.orig/dhcpc.c 2020-12-09 17:23:29.761172785 +0800
+++ udhcp-0.9.8/dhcpc.c 2020-12-09 17:25:33.692550177 +0800
@@ -360,7 +360,7 @@
}
#else
static void dhcp_discover_general(unsigned long *xid, time_t *now){
- if (packet_num < 3) {
+ if (packet_num < X_ZYXEL_RetryCount) {
if (packet_num == 0)
*xid = random_xid();
@@ -374,7 +374,7 @@
/* send discover packet */
send_discover(*xid, requested_ip); /* broadcast */
- timeout = *now + ((packet_num == 2) ? 4 : 2);
+ timeout = *now + ((packet_num == (X_ZYXEL_RetryCount-1)) ? 4 : 2);
packet_num++;
} else {
if (client_config.background_if_no_lease
@@ -617,13 +617,13 @@
break;
case RENEW_REQUESTED:
case REQUESTING:
- if (packet_num < 3) {
+ if (packet_num < X_ZYXEL_RetryCount) {
/* send request packet */
if (state == RENEW_REQUESTED)
send_renew(xid, server_addr, requested_ip, client_config.interface); /* unicast */
else send_selecting(xid, server_addr, requested_ip); /* broadcast */
- timeout = now + ((packet_num == 2) ? 10 : 2);
+ timeout = now + ((packet_num == (X_ZYXEL_RetryCount-1)) ? 10 : 2);
packet_num++;
} else {
/* timed out, go back to init state */
Index: udhcp-0.9.8/options.c
===================================================================
--- udhcp-0.9.8.orig/options.c 2020-12-09 17:23:29.697172786 +0800
+++ udhcp-0.9.8/options.c 2020-12-09 17:24:21.997222832 +0800
@@ -84,6 +84,10 @@
int last_option_index = sizeof(options)/sizeof(struct dhcp_option) - 1;
#endif
+#if 1 // Zyxel, customized retry times of dhcp discover & request (default: 3)
+int X_ZYXEL_RetryCount = 3;
+#endif
+
/* get an option with bounds checking (warning, not aligned). */
unsigned char *get_option(struct dhcpMessage *packet, int code)
{
@@ -318,6 +322,7 @@
while(zcfgFeObjStructGetNext(RDM_OID_DHCPV4_CLIENT, &dhcpIid, (void **)&dhcpcObj) == ZCFG_SUCCESS) {
if ( !strcmp(dhcpcObj->Interface, ipIntf) ){
+ X_ZYXEL_RetryCount = (dhcpcObj->X_ZYXEL_RetryCount > 3) ? dhcpcObj->X_ZYXEL_RetryCount : 3;
found = 1;
free(dhcpcObj);
break;
Index: udhcp-0.9.8/options.h
===================================================================
--- udhcp-0.9.8.orig/options.h 2020-12-09 17:23:29.697172786 +0800
+++ udhcp-0.9.8/options.h 2020-12-09 17:24:47.538167947 +0800
@@ -59,6 +59,10 @@
extern unsigned char sent_config_options[];
#endif
+#if 1 // Zyxel, customized retry times of dhcp discover & request (default: 3)
+extern int X_ZYXEL_RetryCount;
+#endif
+
unsigned char *get_option(struct dhcpMessage *packet, int code);
int end_option(unsigned char *optionptr);
int add_option_string(unsigned char *optionptr, unsigned char *string);