延伸閱讀
- http://www.freedesktop.org/wiki/Software/systemd/
- http://linoxide.com/linux-command/systemd-vs-sysvinit-cheatsheet/
# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4"))
{
send_reply("404", "No destination");
exit;
}
xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
forward("RTF_DISPATCH");
exit;
}
stateful forwarding
# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4"))
{
send_reply("404", "No destination");
exit;
}
xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
t_on_failure("RTF_DISPATCH");
t_relay();
exit;
}
# Sample failure route
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next DST - only for 500 or local timeout
if (t_check_status("500")
or (t_branch_timeout() and !t_branch_replied()))
{
if(ds_next_dst())
{
t_on_failure("RTF_DISPATCH");
t_relay();
exit;
}
}
}
discardroute {
);
}
to one hostroute {
forward(1.2.3.4);
}
或route {
rewritehost(1.2.3.4);
forward();
}
| == | 相等 |
| != | 不相等 |
| =~ | Posix 正規表示式比對。使用 [[:digit:]]{3} 取代 \d\d\d。 |
| > | 大於 |
| >= | greater or equal |
| < | 小於 |
| <= | less or equal |
| && | 邏輯 AND |
| || | 邏輯 OR |
| ! | 邏輯 NOT |
| [ ... ] | test operator - 裡面可以是任何算術式。 |
| bit | field | description |
|---|---|---|
| 2:0 | MUXMODE | pin mux 模式選擇 |
| 3 | PULLUDEN | 0 = 啟用 pull up/down,1 = 停用 |
| 4 | PULLTYPESEL | 0 = pull down, 1 = pull up |
| 5 | RXACTIVE | 0 = output only, 1 = input or output |
| 6 | SLEWCTRL | 選擇 slew rate |
#!KAMAILIO
# 載入模組
loadmodule "sl.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
# 處理 SIP 請求,預設是丟棄
route {
# REGISTER 則 save() 執行 SIP 註冊動作後結束。
if (method=="REGISTER") {
if (!save("location"))
sl_reply_error();
exit;
}
# 其它則 lookup() 查是否有註冊。
if (!lookup("location")) {
# 查詢失敗,回 404 等之後結束。
switch ($rc) {
case -1:
# 查不到
case -3:
# 內部錯誤
sl_send_reply("404", "Not Found");
exit;
case -2:
# 有查到,但 Method 不支援
sl_send_reply("405", "Method Not Allowed");
exit;
}
}
# 如有查到會置換 uri,呼叫內建函數 forward() 將封包轉送。
forward();
}
# SIP 回應預設依 Via 轉送,所以不需要回應處理區塊。
載入的模組說明sudo apt-get install kamailio
sudo vi /etc/default/kamailio將 #RUN_KAMAILIO=yes 行首的 # 移除
sudo service kamailio start
所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...