Merge from Master
[l2tpns.git] / l2tpns.h
index fdfaa62..a5a89f4 100644 (file)
--- a/l2tpns.h
+++ b/l2tpns.h
@@ -15,7 +15,7 @@
 #include <sys/types.h>
 #include <libcli.h>
 
-#define VERSION        "2.2.1-2fdn3.13"
+#define VERSION        "2.2.1-2sames3.14"
 
 // Limits
 #define MAXTUNNEL      500             // could be up to 65535
@@ -24,6 +24,9 @@
 #define MAXADDRESS     20              // Maximum length for the Endpoint Discrminiator address
 #define MAXSESSION     60000           // could be up to 65535
 #define MAXTBFS                6000            // Maximum token bucket filters. Might need up to 2 * session.
+#define MAXSESSINGRP   12              // Maximum number of member links in grouped session
+#define MAXGROUPE              300     // could be up to 65535, Maximum number of grouped session
+#define MAXROUTEINGRP  15              // max static routes per group
 
 // Tunnel Id reserved for pppoe
 #define TUNNEL_ID_PPPOE        1
@@ -217,6 +220,7 @@ enum {
 typedef uint16_t sessionidt;
 typedef uint16_t bundleidt;
 typedef uint16_t tunnelidt;
+typedef uint16_t groupidt;
 typedef uint32_t clockt;
 typedef uint8_t hasht[16];
 
@@ -349,6 +353,35 @@ typedef struct
 }
 sessiont;
 
+typedef struct
+{
+       uint32_t tx_rate;
+       uint32_t prev_coutgrp;
+       sessionidt sid;
+       uint8_t weight;
+}
+groupsesslistt;
+
+typedef struct
+{
+       int state;                              // current state (groupestate enum)
+       uint32_t time_changed;
+       groupidt prev;
+       sessionidt smax;
+       sessionidt smin;
+       groupsesslistt sesslist[MAXSESSINGRP];
+       routet route[MAXROUTEINGRP];            // static routes
+       uint8_t nbroutesgrp;
+       uint8_t nbsession;
+}
+groupsesst;
+
+union iphash
+{
+       sessionidt sess;
+       union iphash *idx;
+};                     // Mapping from IP address to session structures.
+
 typedef struct
 {
         int state;                              // current state (bundlestate enum)
@@ -531,6 +564,13 @@ enum
        BUNDLEUNDEF,            // Undefined
 };
 
+enum
+{
+       GROUPEFREE,             // Not in use
+       GROUPEOPEN,             // Active bundle
+       GROUPEUNDEF             // Undefined
+};
+
 enum
 {
        NULLCLASS = 0,          //End Point Discriminator classes
@@ -741,8 +781,10 @@ typedef struct
        int             cluster_undefined_sessions;     // How many sessions we're yet to receive from the master.
        int             cluster_undefined_bundles;      // How many bundles we're yet to receive from the master.
        int             cluster_undefined_tunnels;      // How many tunnels we're yet to receive from the master.
+       int             cluster_undefined_groupes;      // How many groupes we're yet to receive from the master.
        int             cluster_highest_sessionid;
        int             cluster_highest_bundleid;
+       int             cluster_highest_groupeid;
        int             cluster_highest_tunnelid;
        clockt          cluster_last_hb;                // Last time we saw a heartbeat from the master.
        int             cluster_last_hb_ver;            // Heartbeat version last seen from master
@@ -797,6 +839,7 @@ typedef struct
        int nbmultiaddress; // number multi address to bind
        int indexlacudpfd;      // Index UDP LAC file handle (in udpfd[])
        int nbmultihostname;    // number hostname, normally the same number as the nbudpfd
+       int grp_txrate_average_time; // caculation txrate average time (default 10s)
        int no_throttle_local_IP;       // no throttle traffic from session to session
        in_addr_t bind_n_address[MAX_BINDADDR];
        in_addr_t iftun_n_address[MAX_BINDADDR];
@@ -973,12 +1016,26 @@ int ip_filter(uint8_t *buf, int len, uint8_t filter);
 int cmd_show_ipcache(struct cli_def *cli, const char *command, char **argv, int argc);
 int cmd_show_hist_idle(struct cli_def *cli, const char *command, char **argv, int argc);
 int cmd_show_hist_open(struct cli_def *cli, const char *command, char **argv, int argc);
+void netlink_addattr(struct nlmsghdr *nh, int type, const void *data, int alen);
+ssize_t netlink_send(struct nlmsghdr *nh);
+void cache_ipmap(in_addr_t ip, sessionidt s);
 tunnelidt lac_new_tunnel();
 void lac_tunnelclear(tunnelidt t);
 void lac_send_SCCRQ(tunnelidt t, uint8_t * auth, unsigned int auth_len);
 void lac_send_ICRQ(tunnelidt t, sessionidt s);
 void lac_tunnelshutdown(tunnelidt t, char *reason, int result, int error, char *msg);
 
+// grpsess.c
+sessionidt grp_getnextsession(groupidt g, in_addr_t ip, in_addr_t ip_src);
+void grp_initdata(void);
+void grp_processvendorspecific(sessionidt s, uint8_t *pvs);
+groupidt grp_groupbysession(sessionidt s);
+groupidt grp_groupbyip(in_addr_t ip);
+void grp_setgrouproute(groupidt g, int add);
+void grp_time_changed(void);
+void grp_removesession(groupidt g, sessionidt s);
+int grp_cluster_load_groupe(groupidt g, groupsesst *new);
+
 #undef LOG
 #undef LOG_HEX
 #define LOG(D, s, t, f, ...)   ({ if (D <= config->debug) _log(D, s, t, f, ## __VA_ARGS__); })
@@ -1013,6 +1070,8 @@ extern bundlet *bundle;
 extern sessiont *session;
 extern sessionlocalt *sess_local;
 extern ippoolt *ip_address_pool;
+extern groupsesst *grpsession;
+extern groupidt gnextgrpid;
 #define sessionfree (session[0].next)
 
 
@@ -1025,6 +1084,8 @@ extern struct Tstats *_statistics;
 extern in_addr_t my_address;
 extern int clifd;
 extern int epollfd;
+extern int tunidx;             // ifr_ifindex of tun device
+extern union iphash ip_hash[256];
 
 struct event_data {
        enum {