summaryrefslogtreecommitdiff
authorkejun.gao <kejun.gao@amlogic.com>2011-10-19 03:28:23 (GMT)
committer kejun.gao <kejun.gao@amlogic.com>2011-10-19 03:28:23 (GMT)
commit94e94eb9989d3da1baf8a4a41cc19e3a7c839f4d (patch)
treeee7768e3edfb6e39fa5d6db248e022fd825e3517
parent6ed0dab83a67a9ae270eb0f718e2e207b45e2fb9 (diff)
downloadpppoe-94e94eb9989d3da1baf8a4a41cc19e3a7c839f4d.zip
pppoe-94e94eb9989d3da1baf8a4a41cc19e3a7c839f4d.tar.gz
pppoe-94e94eb9989d3da1baf8a4a41cc19e3a7c839f4d.tar.bz2
1. Fix bug: failed to send PADT when PPPoE connection is closed.
2. Fix bug: failed to get dns server ip when IPCP OK 3. Add feature: Read pppd options from config file
Diffstat
-rwxr-xr-xjni/pppoe_jni.cpp49
-rwxr-xr-xjni/src/pppoe.c7
-rwxr-xr-xjni/src/pppoe_status.c4
-rwxr-xr-xjni/src/pppoe_wrapper.c20
4 files changed, 73 insertions, 7 deletions
diff --git a/jni/pppoe_jni.cpp b/jni/pppoe_jni.cpp
index 5c91401..9040945 100755
--- a/jni/pppoe_jni.cpp
+++ b/jni/pppoe_jni.cpp
@@ -47,7 +47,8 @@ static char pppoe_disconnect_cmd[512] = {"ppp-stop"};
static char pppoe_plugin_cmd[PPPOE_PLUGIN_CMD_LEN_MAX];
-static char pppd_options[] = {"debug logfd 1 noipdefault noauth default-asyncmap defaultroute nodetach mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp lcp-echo-interval 20 lcp-echo-failure 3"};
+#define PPPD_OPTIONS_LEN 512
+static char pppd_options[PPPD_OPTIONS_LEN + 1] = {"debug logfd 1 noipdefault noauth default-asyncmap defaultroute show-password nodetach mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj usepeerdns novjccomp lcp-echo-interval 20 lcp-echo-failure 3"};
@@ -79,6 +80,35 @@ static char* create_pppoe_connect_cmd
return pppoe_connect_cmd;
}
+#define CONFIG_FILE "/system/etc/ppp/pppd_options.conf"
+
+
+
+/* Handy routine to read very long lines in text files.
+ * This means we read the whole line and avoid any nasty buffer overflows. */
+static ssize_t get_line(char **line, size_t *len, FILE *fp)
+{
+ char *p;
+ size_t last = 0;
+
+ while(!feof(fp)) {
+ if (*line == NULL || last != 0) {
+ *len += BUFSIZ;
+ *line = (char*)realloc(*line, *len);
+ }
+ p = *line + last;
+ memset(p, 0, BUFSIZ);
+ if (fgets(p, BUFSIZ, fp) == NULL)
+ break;
+ last += strlen(p);
+ if (last && (*line)[last - 1] == '\n') {
+ (*line)[last - 1] = '\0';
+ break;
+ }
+ }
+ return last;
+}
+
static jboolean com_amlogic_PppoeOperation_connect
(JNIEnv *env, jobject obj, jstring jstr_account, jstring jstr_passwd)
@@ -88,6 +118,23 @@ static jboolean com_amlogic_PppoeOperation_connect
struct pppoe_ctrl * ctrl;
char *p;
+ FILE *f;
+ f = fopen(CONFIG_FILE, "r");
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"Try Open %s", CONFIG_FILE);
+
+ if (f) {
+ char *line, *option, *p, *buffer = NULL;
+ size_t len = 0;
+
+ get_line(&buffer, &len, f);
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,"get_line: [%s]", buffer);
+ if (buffer){
+ strncpy(pppd_options, buffer, sizeof(pppd_options) - 1);
+ free(buffer);
+ }
+ fclose(f);
+ }
+
p_user = (char *)env->GetStringUTFChars(jstr_account, NULL);
p_passwd = (char *)env->GetStringUTFChars(jstr_passwd, NULL);
diff --git a/jni/src/pppoe.c b/jni/src/pppoe.c
index 6fc848c..5809f92 100755
--- a/jni/src/pppoe.c
+++ b/jni/src/pppoe.c
@@ -337,10 +337,10 @@ session(PPPoEConnection *conn)
static void
sigPADT(int src)
{
- syslog(LOG_DEBUG,"Received signal %d on session %d.",
+ syslog(LOG_INFO,"Received signal %d on session %d.",
(int)src, (int) ntohs(Connection->session));
sendPADTf(Connection, "RP-PPPoE: Received signal %d", src);
- exit(EXIT_SUCCESS);
+ //exit(EXIT_SUCCESS);
}
/**********************************************************************
@@ -664,7 +664,8 @@ main(int argc, char *argv[])
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGHUP, sigPADT);
- signal(SIGKILL, sigPADT);
+ signal(SIGUSR1, sigPADT);
+
session(&conn);
return 0;
}
diff --git a/jni/src/pppoe_status.c b/jni/src/pppoe_status.c
index e1f14e3..15de623 100755
--- a/jni/src/pppoe_status.c
+++ b/jni/src/pppoe_status.c
@@ -31,7 +31,7 @@ static int if_is_up(const char *if_name)
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
- __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"if_is_up(%s): failed to create socket\n", if_name);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"if_is_up(%s): failed to create socket(%s)\n", if_name, strerror(errno));
return -1;
}
@@ -39,7 +39,7 @@ static int if_is_up(const char *if_name)
if (ret < 0) {
ret = -errno;
//perror(ifr.ifr_name);
- __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"if_is_up(%s): failed to ioctl()\n", if_name);
+ __android_log_print(ANDROID_LOG_ERROR, LOCAL_TAG,"if_is_up(%s): failed to ioctl(%s)\n", if_name, strerror(errno));
goto done;
}
diff --git a/jni/src/pppoe_wrapper.c b/jni/src/pppoe_wrapper.c
index 672e00f..8cf721f 100755
--- a/jni/src/pppoe_wrapper.c
+++ b/jni/src/pppoe_wrapper.c
@@ -78,10 +78,28 @@ static int ppp_stop()
return -1;
}
+ /*
+ The signals SIGKILL and SIGSTOP cannot
+ be caught, blocked, or ignored.
+ So send SIGUSR1 to notify pppoe to send PADT.
+ */
+ ret = kill(pid, SIGUSR1);
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "Send SIGUSR1 to pid(#%d), ret = %d\n", pid, ret );
+
+ /*
+ If no sleep before send SIGKILL, pppoe will just being killed
+ rather than sending PADT.
+ */
+ __android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
+ "sleep before send SIGKILL to pid(#%d)\n", pid );
+
+ sleep(5);
+
ret = kill(pid, SIGKILL);
__android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
"Send SIGKILL to pid(#%d), ret = %d\n", pid, ret );
-
+
unlink(PPPOE_PIDFILE);
__android_log_print(ANDROID_LOG_INFO, LOCAL_TAG,
"removed %s\n", PPPOE_PIDFILE );