Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

IPTraffic: get hostnames from static DHCP list #1136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion release/src/router/www/client_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,18 @@ function oui_query_web(mac){
function clientFromIP(ip) {
for(var i=0; i<clientList.length;i++){
var clientObj = clientList[clientList[i]];
if(clientObj.ip == ip) return clientObj;
if(clientObj.ip == ip){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mixes a formatting change with a functional change. This is small enough that it doesn't strike me as a problem to have it in the same commit, but seems good to avoid in the future.

return clientObj;
}
}
staticList = originData.staticList;
for(var i=0; i<staticList.length; i++){
if(staticList[i] != ""){
data = staticList[i].split(">");
Copy link

@Thynix Thynix Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on commenting here (or better yet, here?) what the expected format is? I had to go scrounging to find that data[0] is [0] the MAC address and that clientList is indeed keyed by MAC address.

How about: [1]

/* Entries in dhcp_staticlist are formatted as: "MAC>IP>hostname". */
staticList: decodeURIComponent('<% nvram_char_to_ascii("", "dhcp_staticlist"); %>').replace(/&#62/g, ">").replace(/&#60/g, "<").split('<'),

It could also be nice (though I don't feel too strongly about it) to set var static_ip and var static_mac or something from data instead of using them inline and leaving their values more implicit.

EDIT: The bigger picture here is that staticList should perhaps contain objects, not strings that must be split each time. That's definitely a separate change though.

Other than that this LGTM.


[0] Probably? I was able to find nvram_char_to_ascii but not the implementation that reads from nvram. Is it in a binary somewhere? It seems like the larger need is documentation of what's in nvram and in what format, but I haven't run into that yet.

I was able to trace thusly:

but found no definition for nvram_get_x().

[1] assuming the nvram value matches that in index.asp - the behavior of which suggests this is dumped straight into nvram which seems incredibly fragile.

if(data[1] == ip){
return clientList[data[0]];
}
}
}
return 0;
}
Expand Down