Permalink
Browse files

webui: Implement AQoS tracked connection report on QoS Statistics page

Data is retrieved from the bwdpi databases unpacked in /tmp/bwdpi.
  • Loading branch information...
RMerl committed Jan 2, 2019
1 parent 752b814 commit a081dddbf3fb3ff9fbd00497a2dd3992bb4d24eb
@@ -58,6 +58,10 @@

#include <net/route.h>

#ifdef RTCONFIG_BWDPI
#include "bwdpi_common.h"
#endif

int
ej_get_leases_array(int eid, webs_t wp, int argc, char_t **argv)
{
@@ -1070,3 +1074,87 @@ int ej_connlist_array(int eid, webs_t wp, int argc, char **argv) {

return ret;
}

#ifdef RTCONFIG_BWDPI
int ej_bwdpi_conntrack(int eid, webs_t wp, int argc, char **argv_) {
char comma;
char line[128];
FILE *fp;
char src_ip[16], dst_ip[16], prot[4];
int index, dport, sport;
int ret;
unsigned long mark;
static char appdb[32][256][64];
static char catdb[32][32];
static int parsed = 0;
int id, cat;
char desc[65];
// int count = 0;

// Parse App database
if (!parsed) {
fp = fopen(APPDB, "r");
if (!fp) {
// _dprintf("Error opening DB file!\n");
return websWrite(wp, "\nbwdpi_conntrack=[];");
}

while (fgets(line, sizeof(line), fp) != NULL)
{
if (sscanf(line,"%d,%d,%*d,%63[^\n]", &id, &cat, desc) == 3) {
strcpy(appdb[id][cat], desc);
// count++;
}
}
fclose(fp);
// _dprintf("Parsed %d entries (%ld bytes)\n", count, sizeof(db));
// Parse categories

fp = fopen(CATDB, "r");
if (!fp) {
// _dprintf("Error opening Cat file!\n");
return websWrite(wp, "\nbwdpi_conntrack=[];");
}

while (fgets(line, sizeof(line), fp) != NULL)
{
if (sscanf(line,"%d,%31[^\n]", &cat, desc) == 2) {
strcpy(catdb[cat], desc);
}
}
fclose(fp);
parsed = 1;
}

// Parse tracked connections
if ((fp = fopen("/proc/bw_cte_dump", "r")) == NULL)
return websWrite(wp, "\nbwdpi_conntrack=[];");

ret = websWrite(wp, "\nbwdpi_conntrack=[");
comma = ' ';

while (fgets(line, sizeof(line), fp)) {
// ipv4 tcp src=192.168.10.156 dst=172.217.13.110 sport=8248 dport=443 index=8510 mark=3cd000f
if (sscanf(line, "ipv4 %3s src=%15s dst=%15s sport=%d dport=%d index=%d mark=%lx",
prot, src_ip, dst_ip, &sport, &dport, &index, &mark) != 7 ) continue;

id = (mark & 0x3F0000)/0xFFFF;
cat = mark & 0xFFFF;
if ((cat == 0) && (id == 0))
sprintf(desc, "Untracked");
else if ((appdb[id][cat][0] == '\0') || (cat > 256) || (id > 32))
sprintf(desc, "unknown (AppID=%d, Cat=%d)", id, cat);
else
strcpy(desc, appdb[id][cat]);

ret += websWrite(wp, "%c[\"%s\", \"%s\", \"%d\", \"%s\", \"%d\", \"%s\", \"%d\", \"%d\"]",
comma, prot, src_ip, sport, dst_ip, dport, desc, cat, id);
comma = ',';
}

fclose(fp);
ret += websWrite(wp, "];\n");
return ret;
}
#endif

@@ -38,4 +38,8 @@ extern void iptraffic_conntrack_init();
extern void ctvbuf(FILE *f);
#endif

#ifdef RTCONFIG_BWDPI
extern int ej_bwdpi_conntrack(int eid, webs_t wp, int argc, char **argv_);
#endif

int ej_connlist_array(int eid, webs_t wp, int argc, char **argv);
@@ -23123,7 +23123,9 @@ struct ej_handler ej_handlers[] = {
{ "iptmon", ej_iptmon},
{ "ipt_bandwidth", ej_ipt_bandwidth},
#endif

#ifdef RTCONFIG_BWDPI
{ "bwdpi_conntrack", ej_bwdpi_conntrack},
#endif
{ "bandwidth", ej_bandwidth},
#ifdef RTCONFIG_DSL
{ "spectrum", ej_spectrum}, //Ren
@@ -12,12 +12,14 @@
<link rel="stylesheet" type="text/css" href="index_style.css">
<link rel="stylesheet" type="text/css" href="form_style.css">
<link rel="stylesheet" type="text/css" href="usp_style.css">
<link rel="stylesheet" type="text/css" href="/js/table/table.css">
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/chart.min.js"></script>
<script type="text/javascript" src="/state.js"></script>
<script type="text/javascript" src="/help.js"></script>
<script type="text/javascript" src="/general.js"></script>
<script type="text/javascript" src="/popup.js"></script>
<script type="text/javascript" src="/js/table/table.js"></script>
<script>
var qos_type ="<% nvram_get("qos_type"); %>";
@@ -36,6 +38,7 @@ if ("<% nvram_get("qos_enable"); %>" == 0) { // QoS disabled
if (qos_mode == 2) {
var bwdpi_app_rulelist = "<% nvram_get("bwdpi_app_rulelist"); %>".replace(/&#60/g, "<");
var category_title = ["Net Control Packets", "<#Adaptive_Game#>", "<#Adaptive_Stream#>","<#Adaptive_Message#>", "<#Adaptive_WebSurf#>","<#Adaptive_FileTransfer#>", "<#Adaptive_Others#>", "Default"];
var cat_id_array = [[9,20], [8], [4], [0,5,6,15,17], [13,24], [1,3,14], [7,10,11,21,23], []];
@@ -56,6 +59,7 @@ var timedEvent = 0;
var color = ["#B3645B","#B98F53","#C6B36A","#849E75","#2B6692","#7C637A","#4C8FC0", "#6C604F"];
<% get_tcclass_array(); %>;
<% bwdpi_conntrack(); %>;
var pieOptions = {
segmentShowStroke : false,
@@ -103,6 +107,96 @@ function initial(){
show_menu();
refreshRate = document.getElementById('refreshrate').value
get_data();
draw_conntrack_table();
}
function get_qos_class(category, appid){
var i, j, catlist, rules;
if (category == 0 && appid == 0)
return 7;
for (i=0; i < bwdpi_app_rulelist_row.length-2; i++){
rules = bwdpi_app_rulelist_row[i];
// Add categories missing from nvram but always found in qosd.conf
if (i == 0)
rules += ",18,19";
else if (i == 4)
rules += ",28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43";
else if (i == 5)
rules += ",12";
catlist = rules.split(",");
for (j=0; j < catlist.length; j++) {
if (catlist[j] == category){
return i;
}
}
}
return 7;
}
function draw_conntrack_table(){
var i, label;
if (qos_mode !=2) return;
for (i=0; i < bwdpi_conntrack.length; i++) {
label = bwdpi_conntrack[i][5];
bwdpi_conntrack[i][5] = "<span style=\"padding: 4px 8px 4px 8px; color: white; background-color: " + color[get_qos_class(bwdpi_conntrack[i][7], bwdpi_conntrack[i][6])] + ";\">"+label +"</span>";
}
// Remove cat and appid cols
var tabledata = bwdpi_conntrack.map(function(val){
return val.slice(0, -2);
});
var tableStruct = {
data: tabledata,
container: "tableContainer",
title: "Tracked connections",
header: [
{
"title" : "Proto",
"sort" : "str",
"width" : "8%"
},
{
"title" : "Source",
"sort" : "ip",
"width" : "25%"
},
{
"title" : "SPort",
"sort" : "num",
"width" : "8%"
},
{
"title" : "Destination",
"sort" : "ip",
"width" : "25%"
},
{
"title" : "DPort",
"sort" : "num",
"width" : "8%"
},
{
"title" : "Application",
"sort" : "str",
"width" : "26%"
}
]
}
if(tableStruct.data.length) {
tableApi.genTableAPI(tableStruct);
}
}
@@ -159,7 +253,7 @@ function get_data() {
get_data();
},
success: function(response){
redraw();
redraw();draw_conntrack_table();
if (refreshRate > 0)
timedEvent = setTimeout("get_data();", refreshRate * 1000);
}
@@ -311,6 +405,9 @@ function draw_chart(data_array, ctx, pie) {
<td><span id="legend_ul"></span></td>
</tr>
</table>
<br>
<div id="tableContainer" style="margin-top:-10px;"></div>
<br>
<div class="apply_gen" style="padding-top: 25px;"><input type="button" onClick="location.href=location.href" value="<#CTL_refresh#>" class="button_gen"></div>
</td>
</tr>
@@ -1,2 +1,2 @@
<% get_tcclass_array(); %>;

<% bwdpi_conntrack(); %>;

0 comments on commit a081ddd

Please sign in to comment.