20180903_jeffrey - silenceuncrio/diary GitHub Wiki

0910

先把下午的 90 秒演講主題投影片準備好

1035

盤一下 M360-P 的工作

Job End
Web UI: Dual APN Data Usage 9/7
BGP with loopback in route mode 9/7

1050

先做自己的部分

Job End
BGP with loopback in route mode 9/7

基本上自己已經知道怎麼解決這個 issue 了

review 自己先前的努力

1105

M360 LTE 搭配中華電信 SIM 的設定

image

預設的 LTE Net ModeRouter Only

APN1(Router) 預設的 APN 是空值

以台灣的中華電信為例

我們需要在這一欄填入 internet

等到 LTE 連線起來之後

我們可以在 IP AliasInterface 下拉可選欄位發現 eth1(LTE APN1) image

我們需要在這個欄位新增一個 lo(Loopback) 的選項來符合這次 BGP with loopback in route mode 的需求

1140

發現 255.255.255.255 的 Mask 檢查不過

image

目前檢查的 pattern 如下

    vm.regex_netmask = /^((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0)|255\.(0|128|192|224|240|248|252|254)))))$/;

做完以下修正就好了

diff --git a/proscend/prosrc/www/app/feature/ip_alias.js b/proscend/prosrc/www/app/feature/ip_alias.js
index 6ce372a..4171a36 100644
--- a/proscend/prosrc/www/app/feature/ip_alias.js
+++ b/proscend/prosrc/www/app/feature/ip_alias.js
@@ -127,10 +127,12 @@ function ipAliasController($route, icos, config, status) {
         vm.help.interface_options.push({val: vm.status.devices[i], label: vm.status.devices[i]});
     }

+    vm.help.interface_options.push({val: "lo", label: "lo(Loopback)"});^M
+^M


     vm.regex_ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/;
-    vm.regex_netmask = /^((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0)|255\.(0|128|192|224|240|248|252|254)))))$/;
+    vm.regex_netmask = /^((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0\.0)|(255\.(((0|128|192|224|240|248|252|254)\.0)|255\.(0|128|192|224|240|248|252|254|255)))))$/;^M

加 255.255.255.255 的 Mask 的 Addr - 4.4.4.1 並 Apply

image

看一下目前的 interface

root@M360-P:/www/app/feature# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:43:28:80:60
          inet6 addr: fe80::20c:43ff:fe28:8060/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:6202 errors:0 dropped:1 overruns:0 frame:0
          TX packets:5286 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:824015 (804.7 KiB)  TX bytes:2995108 (2.8 MiB)
          Interrupt:3

eth0.2    Link encap:Ethernet  HWaddr 00:0C:43:28:80:60
          inet6 addr: fe80::20c:43ff:fe28:8060/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:12658 (12.3 KiB)

eth1      Link encap:Ethernet  HWaddr 0E:9F:C7:BF:12:F7
          inet addr:10.199.16.78  Bcast:10.199.16.79  Mask:255.255.255.252
          inet6 addr: fe80::c9f:c7ff:febf:12f7/64 Scope:Link
          UP BROADCAST RUNNING NOARP ALLMULTI MULTICAST  MTU:1500  Metric:1
          RX packets:112 errors:0 dropped:0 overruns:0 frame:0
          TX packets:172 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12948 (12.6 KiB)  TX bytes:16841 (16.4 KiB)

lan       Link encap:Ethernet  HWaddr 00:0C:43:28:80:60
          inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:43ff:fe28:8060/64 Scope:Link
          inet6 addr: 2001:b400:e23d:88e::100/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:12838 (12.5 KiB)

lan.1     Link encap:Ethernet  HWaddr 00:0C:43:28:80:60
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:43ff:fe28:8060/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6165 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5203 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:704369 (687.8 KiB)  TX bytes:2979705 (2.8 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:6294 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6294 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:549531 (536.6 KiB)  TX bytes:549531 (536.6 KiB)

lo:ip_alias_0 Link encap:Local Loopback
          inet addr:4.4.4.1  Mask:255.255.255.255
          UP LOOPBACK RUNNING  MTU:65536  Metric:1

Mode: Off 時也沒問題 ifconfig 發現所有 alias 的 interface 都不見了

先 commit 吧

commit b7b94b0543b8aa94134ac3a8e6180647ffb1c635
Refs: [develop]
Author: jeffrey <[email protected]>
Date:   Mon Sep 3 11:56:56 2018 +0800

    add 'lo(Loopback)' interface option at 'Service / IP Alias' web page

 proscend/prosrc/www/app/feature/ip_alias.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

1305

BGP 的 Neighbors 要多一個 update-source 的欄位讓使用者填

目前 BGP factory 的 configuration file 內容如下

{
    "mode": "off",
    "as_number": "1",
    "redistribute_kernel": "off",
    "redistribute_static": "off",
    "redistribute_connected": "off",
    "redistribute_rip": "off",
    "redistribute_ospf": "off",
    "neighbors": [],
    "networks": []
}

由於沒有特別為了 neighbors 的內容作什麼指定

所有沒有必要為了多一個 update-source 欄位作什麼修改

那 icos 從 web 進來的 apply 要因應修改的就是

  • _json_2_setting_handle()
  • _make_configuration_file()

為了這個修改首要的結構改變為 bgp_t

為了相容以前的 configuraion

如果讀到的已存在的 configuration 裡沒有描述 update-source 這個欄位的話

我需要指定一個預設值

1355

icos 的部分改好了

diff --git a/proscend/prosrc/icos/icoslib/bgp/bgp.c b/proscend/prosrc/icos/icoslib/bgp/bgp.c
index de43480..495ef2e 100644
--- a/proscend/prosrc/icos/icoslib/bgp/bgp.c
+++ b/proscend/prosrc/icos/icoslib/bgp/bgp.c
@@ -97,6 +97,9 @@ static int _make_configuration_file(bgp_t *setting)
         return ICOS_FAILURE;
     }

+    fprintf(fp, "hostname Router\n");
+    fprintf(fp, "password zebra\n");
+
     fprintf(fp, "router bgp %s\n", setting->as_number);

     if (setting->redistribute_kernel == ATTVAL_MODE_ON)
@@ -158,6 +161,11 @@ static int _make_configuration_file(bgp_t *setting)
             fprintf(fp, "  neighbor %s ebgp-multihop\n", setting->neighbors[i].ip_address);
         }

+        if (setting->neighbors[i].update_source_mode == ATTVAL_MODE_ON)
+        {
+            fprintf(fp, "  neighbor %s update-source %s\n", setting->neighbors[i].ip_address, setting->neighbors[i].update_source_address);
+        }
+
     }


@@ -333,6 +341,31 @@ static int _json_2_setting_handle(json_object *jobj, bgp_t *setting)
             }
             _LOG_DEBUG("multihop: %d", target->multihop);

+
+            // int neighbors[].update_source_mode;
+            if (json_object_object_get_ex(jobj_neighbor, "update_source_mode", &temp))
+            {
+                const char *str = json_object_get_string(temp);
+                SysGetAttValueByStringSet(str, &target->update_source_mode, commonModeSet, dim(commonModeSet));
+            }
+            else
+            {
+                target->update_source_mode = 0; // off
+            }
+            _LOG_DEBUG("update_source_mode: %d", target->update_source_mode);
+
+            // char neighbors[].update_source_address[STRING32_SIZE];
+            if (json_object_object_get_ex(jobj_neighbor, "update_source_address", &temp))
+            {
+                const char *str = json_object_get_string(temp);
+                snprintf(target->update_source_address, sizeof(target->update_source_address), "%s", str);
+            }
+            else
+            {
+                sprintf(target->update_source_address, "%s", "");
+            }
+            _LOG_DEBUG("update_source_address: %s", target->update_source_address);
+
         }
     }

@@ -430,6 +463,11 @@ static int _setting_2_json_handle(bgp_t *setting, json_object *jobj)
         val_str = SysGetAttStringByStringSet(target->multihop, commonModeSet, dim(commonModeSet));
         json_object_object_add(entry, "multihop", json_object_new_string(val_str));

+        val_str = SysGetAttStringByStringSet(target->update_source_mode, commonModeSet, dim(commonModeSet));
+        json_object_object_add(entry, "update_source_mode", json_object_new_string(val_str));
+
+        json_object_object_add(entry, "update_source_address", json_object_new_string(target->update_source_address));
+
         json_object_array_add(jobj_neighbors, entry);

     }
diff --git a/proscend/prosrc/icos/include/module_bgp.h b/proscend/prosrc/icos/include/module_bgp.h
index bf31358..7b1b6bf 100644
--- a/proscend/prosrc/icos/include/module_bgp.h
+++ b/proscend/prosrc/icos/include/module_bgp.h
@@ -114,6 +114,23 @@ typedef struct
     */
     int multihop;

+
+
+    /*
+    ** Quagga
+    **
+    ** 11.5.2 BGP Peer commands
+    **
+    ** BGP: neighbor peer update-source <ifname|address>
+    **
+    ** Specify the IPv4 source address to use for the BGP session to this neighbour,
+    ** may be specified as either an IPv4 address directly or as an interface name.
+    **
+    */
+    int     update_source_mode;
+    char    update_source_address[STRING32_SIZE];
+
+
 } bgp_neighbor_t;

先搭配一個目前版本的 configuration 如下 - /etc/icos/bgp/bgp.json

{
  "mode":"on",
  "as_number":"1",
  "redistribute_kernel":"on",
  "redistribute_connected":"on",
  "redistribute_static":"off",
  "redistribute_rip":"off",
  "redistribute_ospf":"off",
  "neighbors":[
    {
      "mode":"on",
      "ip_address":"192.168.1.100",
      "as_number":"100",
      "multihop":"on"
    }
  ],
  "networks":[
    {
      "mode":"on",
      "prefix":"168.1.0.0",
      "prefix_length":24
    },
    {
      "mode":"on",
      "prefix":"168.1.1.0",
      "prefix_length":24
    }
  ]
}

1400

搭配舊的 configuration 的情況下

bgp CGI 還是能夠得到 update_source_modeupdate_source_address 的預設值

從 chrome 的 開發人員工具 可以看到 CGI - bgp.cgi?act=config 回傳的內容

image

1545

可以開始作 web ui 了

做好 web ui 先測一下本機的配置是否正確

IP Alias

image

BGP Neighbors

image

ifconfig

root@M360-P:~# ifconfig
...
lo:ip_alias_0 Link encap:Local Loopback
          inet addr:4.4.4.1  Mask:255.255.255.255
          UP LOOPBACK RUNNING  MTU:65536  Metric:1

/etc/quagga/bgpd.conf

hostname Router
password zebra
router bgp 1
  redistribute kernel
  redistribute connected
  neighbor 192.168.1.100 remote-as 100
  neighbor 192.168.1.100 ebgp-multihop
  neighbor 192.168.1.100 update-source 4.4.4.1
log file /tmp/bgpd.log

配置看起來沒什麼問題

可以搭配 M300 來作測試

順便把 M360 上的 wiki update 一下

1655

測試 PASS

wiki 也順便 update

可以 commit 了

commit 0fc92c6aaf2f2c76a7ce036ed5bbceef82818fbc
Refs: [develop], {origin/develop}
Author: jeffrey <[email protected]>
Date:   Mon Sep 3 16:57:04 2018 +0800

    add 2 more fields at 'IP Routing / BGP Neighbors' for user to specify the source address to this neighbor
    - Update Source Mode - Whether to specify the source address to this neighbor
    - Update Source Address - The source address to this neighbor

 proscend/prosrc/icos/icoslib/bgp/bgp.c    | 38 +++++++++++++++++++++++++++++++
 proscend/prosrc/icos/include/module_bgp.h | 17 ++++++++++++++
 proscend/prosrc/www/app/feature/bgp.html  | 31 +++++++++++++++++++++++++
 proscend/prosrc/www/app/feature/bgp.js    | 12 ++++++----
 proscend/prosrc/www/app/locale-en.json    |  2 ++
 proscend/prosrc/www/app/locale-fr.json    |  2 ++
 proscend/prosrc/www/app/locale-zh-tw.json |  2 ++
 7 files changed, 100 insertions(+), 4 deletions(-)

1700

既然 wiki / Known Issue / BGP with Loopback interface 都寫好了

那作個適當的修改就變成 application note 了

可以放在 wiki / How-to / BGP with Loopback interface

1710

剪剪貼貼就寫好了

M360 剩下的工作項目有

Job End
Web UI: Dual APN Data Usage 9/7

順便盤一下 mantis issue

  • 0000198 - (PI) need loop back interface for static route
  • 0000223 - [IP Alias] add interface lan.1 and apply, cause M360P crash
  • 0000222 - [https] login using https fail

0000198 可以關掉了 雖然標題下錯了

1720

來看一下 0000223 - [IP Alias] add interface lan.1 and apply, cause M360P crash

作相同的測試

image

root@M360-P:~# ifconfig
...
lan.1     Link encap:Ethernet  HWaddr 00:0C:43:28:80:78
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:43ff:fe28:8078/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:48658 errors:0 dropped:0 overruns:0 frame:0
          TX packets:41900 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5695329 (5.4 MiB)  TX bytes:16709473 (15.9 MiB)

lan.1:ip_alias_ Link encap:Ethernet  HWaddr 00:0C:43:28:80:78
          inet addr:192.168.10.1  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...

從 PC 端來 ping 這個 interface

image

稍微放一段時間觀察一下 M360 crash 的現象

  • 利用這 alias 出來的 interface 開啟網頁 - 停在 status 畫面
  • PC 端持續 ping 這個 interface

每隔 10 分鐘觀察 M360 的狀況

1730... PASS

1740... PASS

1750... PASS

1800... PASS

1810

放一個晚上觀察一下