このページで
例:最終条件を追加してからファイアウォールに条件を受け入れる
このコミット スクリプトの例では、明示的then accept
なthen accept
ステートメントで終わりのないステートメントをファイアウォール フィルターに追加します。
要件
この例では、Junos OSを実行しているデバイスを使用しています。
概要とコミット スクリプト
Junos OS の各ファイアウォール フィルターは、フィルターの最後に暗示的な破棄アクションを持ち、以下の明示的なフィルター条件に相当します。
term implicit-rule { then discard; }
その結果、パケットがフィルター内の条件のいずれにも一致しない場合、パケットは破棄されます。場合によっては、ファイアウォールフィルターの一連の一致条件に一致しないすべてのパケットを受け入れる最後の条件を追加して、デフォルトを上書きすることができます。この例では、コミットスクリプトは、明示的then accept
なステートメントで終わりのないファイアウォールフィルターに最後then accept
のステートメントを追加します。
このスクリプトの例は、XSLT と SLAX の両方の構文で示されています。
XSLT 構文
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:apply-templates select="firewall/filter | firewall/family/inet | firewall/family/inet6" mode="filter"/> </xsl:template> <xsl:template match="filter" mode="filter"> <xsl:param name="last" select="term[position() = last()]"/> <xsl:comment> <xsl:text>Found </xsl:text> <xsl:value-of select="name"/> <xsl:text>; last </xsl:text> <xsl:value-of select="$last/name"/> </xsl:comment> <xsl:if test="$last and ($last/from or $last/to or not($last/then/accept))"> <xnm:warning> <xsl:call-template name="jcs:edit-path"/> <message> <xsl:text>filter is missing final 'then accept' rule</xsl:text> </message> </xnm:warning> <xsl:call-template name="jcs:emit-change"> <xsl:with-param name="content"> <term> <name>very-last</name> <junos:comment> <xsl:text>This term was added by a commit script</xsl:text> </junos:comment> <then> <accept/> </then> </term> </xsl:with-param> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
SLAX 構文
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { apply-templates firewall/filter | firewall/family/inet | firewall/family/inet6 { mode "filter"; } } match filter { mode "filter"; param $last = term[position() = last()]; <xsl:comment> { expr "Found "; expr name; expr "; last "; expr $last/name; } if ($last and ($last/from or $last/to or not($last/then/accept))) { <xnm:warning> { call jcs:edit-path(); <message> "filter is missing final 'then accept' rule"; } call jcs:emit-change() { with $content = { <term> { <name> "very-last"; <junos:comment> "This term was added by a commit script"; <then> { <accept>; } } } } } }
構成
手順
手順
スクリプトをダウンロード、有効化、テストするには、以下の手順にしたがっています。
スクリプトをテキスト ファイルにコピーし、必要に応じてファイル add-accept.xsl または add-accept.slax に名前を付け、デバイス上の /var/db/scripts/commit/ ディレクトリにコピーします。
以下のテスト構成スタンザを選択し、Ctrl+cを押してクリップボードにコピーします。
スクリプトの SLAX バージョンを使用している場合は、 階層レベルのファイル名を
[edit system scripts commit file]
add-accept.slax に変更します。system { scripts { commit { file add-accept.xsl; } } } firewall { policer sgt-friday { if-exceeding { bandwidth-percent 10; burst-size-limit 250k; } then discard; } family inet { filter test { term one { from { interface t1-0/0/0; } then { count ten-network; discard; } } term two { from { forwarding-class assured-forwarding; } then discard; } } } } interfaces { t1-0/0/0 { unit 0 { family inet { policer output sgt-friday; filter input test; } } } }
設定モードで、 コマンドを
load merge terminal
発行して、スタンザをデバイス設定にマージします。[edit] user@host# load merge terminal [Type ^D at a new line to end input] ... Paste the contents of the clipboard here ...
プロンプトで、マウスと貼り付けアイコンを使用して、クリップボードの内容を貼り付けます。
Enter キーを押します。
Ctrl+dを押します。
設定をコミットします。
user@host# commit
検証
設定の検証
目的
スクリプトが想定どおりに動作していることを確認します。
アクション
コマンドの出力を commit
確認します。このスクリプトでは、すべてのファイアウォールフィルターが明示的 then accept
なステートメントで終わる必要があります。設定スタンザの例には、2つの条件を test
持つフィルターが含まれますが、明示的 then accept
なステートメントは含まれていません。コマンドを commit
発行すると、スクリプトは不足している then accept
ステートメントを追加し、設定をコミットします。コマンドを commit
発行すると、以下の出力が表示されます。
[edit] user@host# commit [edit firewall family inet filter test] warning: filter is missing final 'then accept' rule commit complete
設定モードで、 コマンドを show firewall
発行して、変更された設定を確認します。次の出力が表示されます。
[edit] user@host# show firewall policer sgt-friday { if-exceeding { bandwidth-percent 10; burst-size-limit 250k; } then discard; } family inet { filter test { term one { from { interface t1-0/0/0; } then { count ten-network; discard; } } term two { from { forwarding-class assured-forwarding; } then { discard; } } term very-last { then accept; /* This term was added by a commit script */ } } }