个人邮箱:xiaokeweng@gmail.com 欢迎大家直接发邮件给我共同交流学习
Android5.0中全部在使用的idletimer ndc cmd,共add与remove两条,iptables中的idletimer的主要用功能就是当某个NID处于idle状态,即没有数据包通过,超过timeout时间后上报netlink事件。而在android系统中,刚好利用了iptables的idletimeropetion应用在power管理节能策略中。在framework中只有在链接mobiledata数据流量作为default网络时候,才会设置iptableidletimer相关规则。
-
idletimer
<remove|add> <iface> <timeout> <type>
(1)Netd.CommanderListener初始化后:
调用函数:
mangle 表:createChildChains(V4V6,"raw", "PREROUTING", RAW_PREROUTING); createChildChains(V4V6,"mangle", "POSTROUTING", MANGLE_POSTROUTING); sIdletimerCtrl->setupIptablesHooks();
-N idletimer_mangle_POSTROUTING
-A POSTROUTING -j idletimer_mangle_POSTROUTINGraw表:
-N idletimer_raw_PREROUTING
-A PREROUTING -j idletimer_raw_PREROUTING
(2)开启mobiledata作为上行网络时:
调用函数:
mangle 表增加规则:sIdletimerCtrl->addInterfaceIdletimer( [iface], [timeout], [laber]))
-A idletimer_mangle_POSTROUTING -o ccmni0 -j IDLETIMER --timeout 5--label 0 --send_nl_msg 1raw表增加规则:
-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.