それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。
") }) jQuery.noConflict()(document).ready(function(){ /**ページャーが気に入らないので修正**/ //やるべきこと // pre・next のいれかえ jQuery('span.pager-next').insertAfter('span.pager-prev') // pre/next に矢印を入れる jQuery('a[rel=next]').text(jQuery('a[rel=next]').text()+"> ") jQuery('a[rel=prev]').text("< "+jQuery('a[rel=prev]').text()) // pre/next をヘッダにもってくる //jQuery(".date.first").css("display","inline-block") jQuery('div.permalink.pager').clone().insertAfter(".date.first") jQuery("header .pager a").css("padding","0px 15px"); //pre/next をAjaxで取得してタイトルを取る。 //取得したタイトルをpre/next のタイトルに jQuery('span.pager-next,span.pager-prev').css("display","inline-block") jQuery('span.pager-next,span.pager-prev').css("width","250px"); jQuery('span.pager-next,span.pager-prev').css("overflow", "hidden"); jQuery('span.pager-next,span.pager-prev').css("white-space", "nowrap"); jQuery('span.pager-next,span.pager-prev').css("text-overflow", "ellipsis"); jQuery("a[rel=next],a[rel=prev]").each(function(idx,e){ var anchor = e jQuery.get(anchor.href,null,function(html){ jQuery(anchor).text() var title = jQuery("
").html(html).find(".entry-title").text().trim() jQuery(anchor).attr("title", title); text = jQuery(anchor).text() text = text.slice(0,10); text = text.replace(/の記事/, "の記事 ["+title+"] "); jQuery(anchor).text(text) }) }); }); })

nft で指定位置にinsert する

nft で指定位置にinsert する

既存のルールが次のようになっているとき

table inet fw4 {
  chain forward { # handle 2
    type filter hook forward priority filter; policy drop;
    $EXISTS_RULE # handle 2340
    $EXISTS_RULE # handle 2341
    $EXISTS_RULE # handle 2345
    $EXISTS_RULE # handle 2346
    jump handle_reject # handle 2352
  }
}

指定位置(jump handle_reject 2532 ) の直前にルールを入れたい

nft insert rule inet fw4 forward position 2352 mark 666 counter accept

結果は次のようになっている

table inet fw4 {
  chain forward { # handle 2
    type filter hook forward priority filter; policy drop;
    $EXISTS_RULE # handle 2340
    $EXISTS_RULE # handle 2341
    $EXISTS_RULE # handle 2345
    $EXISTS_RULE # handle 2346
    meta mark 0x0000029a accept # handle 2563 <=== 挿入
    jump handle_reject # handle 2352
  }
}

HANDLEを探す

末尾の一つ前に入れたいとき、特定のルールの直前に入れたいときなどあるだろうが、grep して探すしか無い。

GREPできるようなコメントがとても重要になってくる。

TBL='inet fw4'
CHAIN='foward'
UNIQUE='handle_reject'
nft -a list chain $TBL $CHAIN | grep handle_reject | grep -oP '(?<=handle )+\d+'

ユニークなコメントが有ると、ハンドル探索が楽。

TBL='my_table'
UNIQUE_COMMENT=':Quu9xeik'
nft -a list table $TBL | grep $UNIQUE_COMMENT | grep -oP '(?<=handle )+\d+'

直後はADD

insert の変わりに、ADDもできる

nft add rule $TBL $CHAIN position 2352 mark 666 counter accept

指定位置のinsertが便利

特定のルールの直前に挿入(INSERT)と特定のルールの直後に追加(ADD)をができるのは、nftの特徴で便利。

ファイアウォールは先頭の一つあとや末尾の1つまえをよく使うと思うので、よく使う挿入箇所はショートカット出来てほしいところ・・・悩ましい。