|
@@ -31,7 +31,7 @@ typedef struct {
|
|
|
netswitch_info_t sw2;
|
|
netswitch_info_t sw2;
|
|
|
|
|
|
|
|
int ipflag;
|
|
int ipflag;
|
|
|
- char ipaddr[64];
|
|
|
|
|
|
|
+ char host_ip[64];
|
|
|
int port_start;
|
|
int port_start;
|
|
|
}ns_handle_t;
|
|
}ns_handle_t;
|
|
|
static ns_handle_t nsHandle;
|
|
static ns_handle_t nsHandle;
|
|
@@ -424,6 +424,10 @@ static int get_port_start(char *ip)
|
|
|
int port=-1,val;
|
|
int port=-1,val;
|
|
|
netsnmp_variable_list *var,*pvar;
|
|
netsnmp_variable_list *var,*pvar;
|
|
|
|
|
|
|
|
|
|
+#ifdef SW_STATIC_PORT_START
|
|
|
|
|
+ return SW_PORT_START;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
char *ifEntry="1.3.6.1.2.1.2.2";
|
|
char *ifEntry="1.3.6.1.2.1.2.2";
|
|
|
var = snmp_getbulk(SNMP_VERSION_2c, "public", ip, ifEntry);
|
|
var = snmp_getbulk(SNMP_VERSION_2c, "public", ip, ifEntry);
|
|
|
if(var) {
|
|
if(var) {
|
|
@@ -457,30 +461,56 @@ static int get_port_start(char *ip)
|
|
|
|
|
|
|
|
return port;
|
|
return port;
|
|
|
}
|
|
}
|
|
|
|
|
+static int get_hostnet(char *hnet, char *hip)
|
|
|
|
|
+{
|
|
|
|
|
+ char *p=NULL;
|
|
|
|
|
+
|
|
|
|
|
+ strcpy(hnet, hip);
|
|
|
|
|
+ p = strrchr(hnet, '.');
|
|
|
|
|
+ if(!p) {
|
|
|
|
|
+ p = strrchr(hnet, ':');
|
|
|
|
|
+ if(!p) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ p[1] = '0'; p[2] = 0;
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+static int set_ip(char *ip)
|
|
|
|
|
+{
|
|
|
|
|
+ char temp[200];
|
|
|
|
|
+ sprintf(temp, "ip addr add dev eth0 %s/24", ip);
|
|
|
|
|
+ return system(temp);
|
|
|
|
|
+}
|
|
|
|
|
+static int set_gw(char *gw)
|
|
|
|
|
+{
|
|
|
|
|
+ char temp[200];
|
|
|
|
|
+ sprintf(temp, "route del default; route add default gw %s", gw);
|
|
|
|
|
+ return system(temp);
|
|
|
|
|
+}
|
|
|
static int sw_get(netswitch_info_t *sw)
|
|
static int sw_get(netswitch_info_t *sw)
|
|
|
{
|
|
{
|
|
|
int i,j,r,find=0;
|
|
int i,j,r,find=0;
|
|
|
- char temp[100];
|
|
|
|
|
|
|
+ char temp[200];
|
|
|
netswitch_info_t tmp;
|
|
netswitch_info_t tmp;
|
|
|
netsnmp_variable_list *var,*pvar;
|
|
netsnmp_variable_list *var,*pvar;
|
|
|
ns_handle_t *h=&nsHandle;
|
|
ns_handle_t *h=&nsHandle;
|
|
|
|
|
|
|
|
if(h->ipflag==0) {
|
|
if(h->ipflag==0) {
|
|
|
-#ifdef USE_STATIC_IP
|
|
|
|
|
- strcpy(h->ipaddr, SW_HOST_IP);
|
|
|
|
|
- sprintf(temp, "%ip addr add %s", SW_PDU_IP);
|
|
|
|
|
- r = system(temp);
|
|
|
|
|
- if(r) {
|
|
|
|
|
- LOGE("____set pdu ip failed\n");
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+#ifdef SW_STATIC_IP
|
|
|
|
|
+ char hnet[100];
|
|
|
|
|
+ strcpy(h->host_ip, SW_HOST_IP);
|
|
|
|
|
+ //get_hostnet(hnet, h->host_ip);
|
|
|
|
|
+ //sprintf(temp, "ip addr add dev eth0 %s/24; ip route add %s/24 via %s", SW_PDU_IP, hnet, h->host_ip);
|
|
|
|
|
+ //set_ip(SW_PDU_IP); set_gw(h->host_ip);
|
|
|
h->ipflag = 1;
|
|
h->ipflag = 1;
|
|
|
#else
|
|
#else
|
|
|
- r = get_ipaddr(AF_INET, "eth0", h->ipaddr);
|
|
|
|
|
|
|
+ r = get_ipaddr(AF_INET, "eth0", h->host_ip);
|
|
|
if(r) {
|
|
if(r) {
|
|
|
LOGE("____get ip4 failed\n");
|
|
LOGE("____get ip4 failed\n");
|
|
|
|
|
|
|
|
- r = get_ipaddr(AF_INET6, "eth0", h->ipaddr);
|
|
|
|
|
|
|
+ r = get_ipaddr(AF_INET6, "eth0", h->host_ip);
|
|
|
if(r) {
|
|
if(r) {
|
|
|
LOGE("____get ip6 failed\n");
|
|
LOGE("____get ip6 failed\n");
|
|
|
return -1;
|
|
return -1;
|
|
@@ -489,17 +519,17 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
h->ipflag = 1;
|
|
h->ipflag = 1;
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
- //LOGD("___local ip: %s\n", h->ipaddr);
|
|
|
|
|
|
|
+ //LOGD("___local ip: %s\n", h->host_ip);
|
|
|
|
|
|
|
|
if(h->port_start==-1) {
|
|
if(h->port_start==-1) {
|
|
|
- h->port_start = get_port_start(h->ipaddr);
|
|
|
|
|
|
|
+ h->port_start = get_port_start(h->host_ip);
|
|
|
if(h->port_start==-1) {
|
|
if(h->port_start==-1) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
char *dot1dTpFdbEntryOid="1.3.6.1.2.1.17.4.3.1";
|
|
char *dot1dTpFdbEntryOid="1.3.6.1.2.1.17.4.3.1";
|
|
|
- var = snmp_getbulk(SNMP_VERSION_2c, "public", h->ipaddr, dot1dTpFdbEntryOid);
|
|
|
|
|
|
|
+ var = snmp_getbulk(SNMP_VERSION_2c, "public", h->host_ip, dot1dTpFdbEntryOid);
|
|
|
if(var) {
|
|
if(var) {
|
|
|
char *tok_mac="Hex-STRING: ", *tok_id="INTEGER: ";
|
|
char *tok_mac="Hex-STRING: ", *tok_id="INTEGER: ";
|
|
|
|
|
|
|
@@ -525,6 +555,8 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
if(p) {
|
|
if(p) {
|
|
|
p += strlen(tok_id);
|
|
p += strlen(tok_id);
|
|
|
tmp.port[j].id = atoi(p) - h->port_start;
|
|
tmp.port[j].id = atoi(p) - h->port_start;
|
|
|
|
|
+ //LOGD("____%d___id: %s, port_start: %d, id: %d\n", j, p, h->port_start, tmp.port[j].id);
|
|
|
|
|
+
|
|
|
j++;
|
|
j++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -547,7 +579,7 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
char *ipNetToMediaEntryOid="1.3.6.1.2.1.4.22.1";
|
|
char *ipNetToMediaEntryOid="1.3.6.1.2.1.4.22.1";
|
|
|
- var = snmp_getbulk(SNMP_VERSION_2c, "public", h->ipaddr, ipNetToMediaEntryOid);
|
|
|
|
|
|
|
+ var = snmp_getbulk(SNMP_VERSION_2c, "public", h->host_ip, ipNetToMediaEntryOid);
|
|
|
if(var) {
|
|
if(var) {
|
|
|
char *tok_mac="STRING: ", *tok_ip="IpAddress: ";
|
|
char *tok_mac="STRING: ", *tok_ip="IpAddress: ";
|
|
|
|
|
|
|
@@ -595,7 +627,7 @@ static int sw_get(netswitch_info_t *sw)
|
|
|
char *ifEntry="1.3.6.1.2.1.2.2.1.8";
|
|
char *ifEntry="1.3.6.1.2.1.2.2.1.8";
|
|
|
for(i=0; i<SW_PORT_MAX; i++) {
|
|
for(i=0; i<SW_PORT_MAX; i++) {
|
|
|
sprintf(temp, "%s.%d", ifEntry, i+h->port_start);
|
|
sprintf(temp, "%s.%d", ifEntry, i+h->port_start);
|
|
|
- var = snmp_get(SNMP_VERSION_2c, "public", h->ipaddr, temp);
|
|
|
|
|
|
|
+ var = snmp_get(SNMP_VERSION_2c, "public", h->host_ip, temp);
|
|
|
if(var) {
|
|
if(var) {
|
|
|
int id;
|
|
int id;
|
|
|
char *p,*tok_ifo="ifOperStatus.";
|
|
char *p,*tok_ifo="ifOperStatus.";
|
|
@@ -687,6 +719,18 @@ static int get_prod_id(void)
|
|
|
{
|
|
{
|
|
|
return __globalDeviceManage._globalDevInfo.product_id;
|
|
return __globalDeviceManage._globalDevInfo.product_id;
|
|
|
}
|
|
}
|
|
|
|
|
+static int sw_save(sqlite3 *db, netswitch_info_t *old, netswitch_info_t *new)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+ for(i=0; i<SW_PORT_MAX; i++) {
|
|
|
|
|
+ if(memcmp(&old->port[i], &new->port[i], sizeof(netswitch_info_t))) {
|
|
|
|
|
+ dev_switch_update_port(db, &new->port[i]);
|
|
|
|
|
+ //LOGD("____ i: %d, id: %d\n", i, new->port[i].id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
static int sw_alarm(netswitch_evts_t *evts, netswitch_info_t *old, netswitch_info_t *new)
|
|
static int sw_alarm(netswitch_evts_t *evts, netswitch_info_t *old, netswitch_info_t *new)
|
|
|
{
|
|
{
|
|
|
int r=-1;
|
|
int r=-1;
|
|
@@ -701,9 +745,6 @@ static int sw_alarm(netswitch_evts_t *evts, netswitch_info_t *old, netswitch_inf
|
|
|
|
|
|
|
|
alarm_str[0] = 0;
|
|
alarm_str[0] = 0;
|
|
|
for(i=0; i<SW_PORT_MAX; i++) {
|
|
for(i=0; i<SW_PORT_MAX; i++) {
|
|
|
- if(i<SW_PORT_INDEX_START || i>SW_PORT_INDEX_END) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
temp[0] = 0;
|
|
temp[0] = 0;
|
|
|
if(evts->evt[i].cab) {
|
|
if(evts->evt[i].cab) {
|
|
@@ -725,7 +766,7 @@ static int sw_alarm(netswitch_evts_t *evts, netswitch_info_t *old, netswitch_inf
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(flag) {
|
|
if(flag) {
|
|
|
- r = dev_insert_alarm_info(get_db(), get_prod_id(), 1, time_str, alarm_str);
|
|
|
|
|
|
|
+ r = dev_insert_alarm_info(get_db(), get_prod_id(), 0, time_str, alarm_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
return r;
|
|
@@ -746,6 +787,8 @@ static void* sw_thread(void *arg)
|
|
|
r = sw_get(&nh->sw2);
|
|
r = sw_get(&nh->sw2);
|
|
|
if(r==0 && sw_chk(&nh->sw, &nh->sw2, &evts)) {
|
|
if(r==0 && sw_chk(&nh->sw, &nh->sw2, &evts)) {
|
|
|
sw_alarm(&evts, &nh->sw, &nh->sw2);
|
|
sw_alarm(&evts, &nh->sw, &nh->sw2);
|
|
|
|
|
+ sw_save(db, &nh->sw, &nh->sw2);
|
|
|
|
|
+
|
|
|
sw_cpy(&nh->sw, &nh->sw2);
|
|
sw_cpy(&nh->sw, &nh->sw2);
|
|
|
}
|
|
}
|
|
|
sleep(1);
|
|
sleep(1);
|