Android系统中iptables的应用(五)IdlertimerController

个人邮箱:xiaokeweng@gmail.com  欢迎大家直接发邮件给我共同交流学习

       Android5.0
中全部在使用的idletimer ndc cmd,共addremove两条,iptables中的idletimer的主要用功能就是当某个NID处于idle状态,即没有数据包通过,超过timeout时间后上报netlink事件。而在android系统中,刚好利用了iptablesidletimeropetion应用在power管理节能策略中。在framework中只有在链接mobiledata数据流量作为default网络时候,才会设置iptableidletimer相关规则。

 idletimer

 <remove|add> <iface> <timeout> <type>


(1)Netd.CommanderListener
初始化后:

调用函数:

createChildChains(V4V6,"raw", "PREROUTING", RAW_PREROUTING);
createChildChains(V4V6,"mangle", "POSTROUTING", MANGLE_POSTROUTING);
sIdletimerCtrl->setupIptablesHooks();
mangle 表:
-N idletimer_mangle_POSTROUTING
-A POSTROUTING -j idletimer_mangle_POSTROUTING

raw表:
-N idletimer_raw_PREROUTING
-A PREROUTING -j idletimer_raw_PREROUTING

(2)开启mobiledata作为上行网络时:

调用函数:

sIdletimerCtrl->addInterfaceIdletimer( [iface], [timeout], [laber])) 
mangle 表增加规则:
-A idletimer_mangle_POSTROUTING -o ccmni0 -j IDLETIMER --timeout 5--label 0 --send_nl_msg 1

raw表增加规则:
-Aidletimer_raw_PREROUTING -i ccmni0 -j IDLETIMER --timeout 5 --label 0--send_nl_msg 1

示例中,两条规则能够在ifaceccmni0处于idle状态5s后上报netlink事件给framework层。触发后timer重新计数。

(3)IDLETIMER

Thistarget can be used to identify when interfaces have been idle for acertain period of time. Timers are identified by labels andare created when a rule is set with a new label. The rules also takea timeout value (in seconds) as an option. If more than one ruleuses the same timer label, the timer will be restarted whenever any of the rules get a hit. One entry for each timer is created insysfs. This attribute contains the timer remaining for the timer toexpire. The attributes are located under the xt_idletimer class:

/sys/class/xt_idletimer/timers/<label>

Whenthe timer expires, the target module sends a sysfs notification tothe userspace, which can then decide what to do (eg. disconnect tosave power).

--timeoutamount

    Thisis the time in seconds that will trigger the notification.

--labelstring

    Thisis a unique identifier for the timer. The maximum length for thelabel string is 27 characters.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值