20200110_jeffrey - silenceuncrio/diary GitHub Wiki
0905
review
整理一下目前 gre 對於 share memory 的利用方式
1305
icos_shm.h
typedef enum
{
SHM_WAN_ETH = 0,
...
SHM_ID_GRE_TUNNELS, // use ICOS_shm_status_getPtr to get SHM_STATUS_GRE_TUNNEL gre_tunnels
SHM_ID_GRE_TUNNEL_INTF_DOWN, // use ICOS_shm_status_update to update gre_tunnels.tunnels[value].intf_down
SHM_ID_GRE_TUNNEL_KEEPALIVE_COUNTER, // use ICOS_shm_status_update to update gre_tunnels.tunnels[value].keepalive_counter
} SHM_ID; //nameid
typedef struct
{
struct
{
int intf_down; // (default)0: up; 1: down
int keepalive_counter; // default(0)
} tunnels[2];
} SHM_STATUS_GRE_TUNNELS;
typedef struct _shm_map_status
{
...
SHM_STATUS_GRE_TUNNELS gre_tunnels;
} SHM_MAP_STATUS;
icos_ipc.c
static SHM_MAP_STATUS *GMShmMap=NULL;
int ICOS_shm_status_update(int namid, int value, void *vdat)
{
if (!GMShmMap)
{
if (ICOS_shm_status_open()!=ICOS_SUCCESS)
{
CPRT("SHM: id=%d val=%d\n", namid, value);
return ICOS_FAILURE;
}
}
PRO_MUTEX_LOCK(Gshm_mux);
switch (namid)
{
case SHM_WAN_ETH:
memcpy(&(GMShmMap->eth), vdat, sizeof(ND_NP_IP));
break;
...
case SHM_ID_GRE_TUNNEL_INTF_DOWN:
memcpy(&(GMShmMap->gre_tunnels.tunnels[value].intf_down), vdat, sizeof(int));
break;
case SHM_ID_GRE_TUNNEL_KEEPALIVE_COUNTER:
memcpy(&(GMShmMap->gre_tunnels.tunnels[value].keepalive_counter), vdat, sizeof(int));
break;
default:
CPRT("SHM: id=%d error\n", namid);
break;
}
PRO_MUTEX_UNLOCK(Gshm_mux);
return ICOS_SUCCESS;
}
void *ICOS_shm_status_getPtr(int namid)
{
if (!GMShmMap)
{
if (ICOS_shm_status_open()!=ICOS_SUCCESS)
{
CPRT("SHM: id=%d\n", namid);
return NULL;
}
}
switch (namid)
{
case SHM_WAN_ETH:
return (void *)&(GMShmMap->eth);
...
case SHM_ID_GRE_TUNNELS:
return (void *)&GMShmMap->gre_tunnels;
break;
}
return NULL;
}
icospromsg.c
void shm_init(void)
{
shm_status_open();
gModuleStatusp=ICOS_shm_status_get();
if (gModuleStatusp)
{
memset(gModuleStatusp, 0, sizeof(SHM_MAP_STATUS));
}
else
{
gModuleStatusp=NULL;
}
}
利用 webcgi - icos_shm.c 來提供給 web ui 呈現 gre tunnels 的 information
static _gre_tunnels()
{
SHM_STATUS_GRE_TUNNELS *gre_tunnels = ICOS_shm_status_getPtr(SHM_ID_GRE_TUNNELS);
if (gre_tunnels == NULL)
{
jweb.http.status(500);
jweb.out.json.fail("ICOS_shm_status_getPtr fail");
}
json_object *shm = json_object_new_object();
json_object *tunnels = json_object_new_array();
for (int i = 0; i < 2; i ++)
{
json_object *entry = json_object_new_object();
json_object_object_add(entry, "intf_down", json_object_new_int(gre_tunnels->tunnels[0].intf_down));
json_object_object_add(entry, "keepalive_counter", json_object_new_int(gre_tunnels->tunnels[0].keepalive_counter));
json_object_array_add(tunnels, entry);
}
json_object_object_add(shm, "tunnels", tunnels);
jweb.out.json.data("shm", shm);
}
static void _shm()
{
char *name = jweb.cgi.get("name");
if (!name)
{
jweb.out.json.fail("name needed");
}
if (STRCMP(name, "lan_status"))
{
_lan_status();
}
...
else if (STRCMP(name, "gre_tunnels"))
{
_gre_tunnels();
}
else
{
jweb.http.status(400);
jweb.out.json.fail("name invalid");
}
}
int main(void)
{
jweb.cgi.init();
if (STRCMP(jweb.in.act, "shm"))
{
_shm();
}
else
{
jweb.http.status(400);
jweb.out.json.fail("act invalid");
}
}
實際做事的 grek - GRE Tunnel Keepalive
void my_packet_handler(
u_char *args,
const struct pcap_pkthdr* header,
const u_char* packet
)
{
const struct sniff_ethernet *ethernet; /* The ethernet header */
const struct sniff_ip *ip; /* The IP header */
const struct sniff_gre *gre; /* The GRE header */
u_int size_ip;
ethernet = (struct sniff_ethernet*)(packet);
ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
size_ip = IP_HL(ip)*4;
//printf("size_ip: %u\n", size_ip);
if (size_ip < 20)
{
printf(" * Invalid IP header length: %u bytes\n", size_ip);
return;
}
gre = (struct sniff_gre*)(packet + SIZE_ETHERNET + size_ip);
//printf("gre->protocol: %u\n", gre->protocol);
// The tunnel keepalive counter is then reset to 0 and the packet is discarded.
Tunnel_keepalive_counter = 0;
// update to share memory for the others interesting to this informaiton
ICOS_shm_status_update(SHM_ID_GRE_TUNNEL_KEEPALIVE_COUNTER, 0, &Tunnel_keepalive_counter);
}
static void handler(int sig, siginfo_t *si, void *uc)
{
printf("(Tunnel_interface_up, Tunnel_keepalive_counter) = (%d, %d)\n", Tunnel_interface_up, Tunnel_keepalive_counter);
if (Tunnel_interface_up && (Tunnel_keepalive_counter > Keepalive_retries))
{
Tunnel_interface_up = false;
// update to share memory for the others interesting to this informaiton
int down = 1;
ICOS_shm_status_update(SHM_ID_GRE_TUNNEL_INTF_DOWN, 0, &down);
char cmd[64];
sprintf(cmd, "ifconfig %s down", Tunnel_name);
printf("system cmd: %s\n", cmd);
system(cmd);
}
if (!Tunnel_interface_up && Tunnel_keepalive_counter == 0)
{
Tunnel_interface_up = true;
// update to share memory for the others interesting to this informaiton
int down = 0;
ICOS_shm_status_update(SHM_ID_GRE_TUNNEL_INTF_DOWN, 0, &down);
char cmd[64];
sprintf(cmd, "ifconfig %s up", Tunnel_name);
printf("system cmd: %s\n", cmd);
system(cmd);
}
if (sendto(Sd, &Buffer, sizeof(struct grehdr) + sizeof(struct iphdr) + sizeof(struct grehdr), 0,
(struct sockaddr*) &Dest, sizeof(struct sockaddr)) < 0)
{
printf("sendto() failed!\n");
}
else
{
// Increments the tunnel keepalive counter by one.
Tunnel_keepalive_counter ++;
// update to share memory for the others interesting to this informaiton
ICOS_shm_status_update(SHM_ID_GRE_TUNNEL_KEEPALIVE_COUNTER, 0, &Tunnel_keepalive_counter);
}
}
這樣一來使用者從 web ui 也能得知每個 GRE tunnel 目前的 interface 是 up 或 down
以及 keepalive 的 conunter
不過也發現 grek 需要額外的參數 gre tunnel index
這樣才能 update 到正確的 share memory
順手加一下
感覺 grek 可以順手寫到 syslog 去
1645
差不多可以上 code 了
m330[release/v0.08] - GRE support tunnel keepalive
commit 1238157773aa566e047b7877b0b526c9239915e6
Refs: [release/v0.08], {origin/release/v0.08}
Author: jeffrey <[email protected]>
Date: Fri Jan 10 16:46:24 2020 +0800
GRE support tunnel keepalive
.../rootfs/home/factory/icos/gre_3g/gre_3g.json | 31 ++
proscend/mconfig/Config.in | 1 +
proscend/mconfig/configs/CTCU/0_CTCU/defconfig | 3 +-
.../mconfig/configs/CTCU/1_CTCU_WIFI/defconfig | 3 +-
.../mconfig/configs/GENERIC/0_GENERIC/defconfig | 4 +-
.../configs/GENERIC/1_GENERIC_WIFI/defconfig | 4 +-
proscend/mconfig/configs/HYTEC/0_HYTEC/defconfig | 3 +-
.../mconfig/configs/HYTEC/1_HYTEC_WIFI/defconfig | 3 +-
.../mconfig/configs/HYTEC/2_HYTEC_KOREA/defconfig | 3 +-
proscend/mconfig/configs/PI/0_PI_WIFI/defconfig | 3 +-
proscend/prosrc/icos/greK/main.c | 81 ++-
proscend/prosrc/icos/icoslib/Makefile | 4 +
proscend/prosrc/icos/icoslib/entry.c | 7 +
proscend/prosrc/icos/icoslib/gre_3g/Makefile | 14 +
proscend/prosrc/icos/icoslib/gre_3g/gre_3g.c | 605 +++++++++++++++++++++
.../prosrc/icos/icoslib/ipc_utility/icos_ipc.c | 9 +
proscend/prosrc/icos/include/icos_common.h | 1 +
proscend/prosrc/icos/include/icos_module.h | 1 +
proscend/prosrc/icos/include/icos_shm.h | 18 +
proscend/prosrc/icos/include/module_gre_3g.h | 43 ++
proscend/prosrc/webcgi/Makefile | 4 +
proscend/prosrc/webcgi/gre_3g.c | 105 ++++
proscend/prosrc/webcgi/icos_shm.c | 30 +
proscend/prosrc/www/Makefile | 1 +
proscend/prosrc/www/app/feature/gre_3g.js | 126 +++++
proscend/prosrc/www/app/feature/gre_3g_edit.html | 147 +++++
.../prosrc/www/app/feature/gre_3g_summary.html | 78 +++
proscend/prosrc/www/app/locale-en.json | 29 +
proscend/prosrc/www/app/locale-fr.json | 29 +
proscend/prosrc/www/app/locale-zh-tw.json | 29 +
proscend/prosrc/www/app/services/icos.service.js | 14 +
.../prosrc/www/src/app/feature/gre_3g.html.src | 3 +
proscend/prosrc/www/src/index.html.src | 3 +-
proscend/prosrc/www/src/menu.html.src | 7 +-
34 files changed, 1413 insertions(+), 33 deletions(-)
可以寫週報了
M300[release/v2.02] - offer a checkbox to control whether auto show the setting wizard at 'Management > Administration' page
m330[release/v0.08]
- at 'WAN > WiFi STA' web page, do not get the status until vm.status.scan_count != 0
- implement grek - GRE Tunnel Keepalive
- add 'Country Code' field at 'WAN > WiFi STA' web page
- suitable label for different priority at 'WAN > Priority' web page
- GRE support tunnel keepalive
M300
- P1 - Can you give us a check box where we can turn OFF the startup wizard
M330
- P1 - Driving GRE keepalive from M330 - greK (by jessy)
- P2 - Web UI: GPS Track drawing (Server)
M360P - none