ZeroTierOne icon indicating copy to clipboard operation
ZeroTierOne copied to clipboard

Fix how MAC addresses are handled by the rules parser

Open lel-amri opened this issue 1 year ago • 2 comments

Fixes https://github.com/zerotier/ZeroTierOne/issues/2175.

It wasn't ignoring separator characters such as the colon and hyphen. The rules compiler automatically add a colon to separate bytes, which is not compatible with how they are parsed.


This is currently a draft, as I'm not particularly versed in C++, and I think I couldn't fit well with the style used at Zerotier Inc.

lel-amri avatar Nov 14 '23 21:11 lel-amri

Thanks for doing this. We will try to test it soon. Do you have a quick sample ruleset that shows the problem?

laduke avatar Nov 15 '23 16:11 laduke

I think a direct and minimal test would be the following ruleset:

drop macsrc AA:AA:AA:AA:AA;
accept;

which compiles to the following JSON:

{
 "rules": [
  {
   "type": "MATCH_MAC_SOURCE",
   "not": false,
   "or": false,
   "mac": "aa:aa:aa:aa:aa"
  },
  {
   "type": "ACTION_DROP"
  },
  {
   "type": "ACTION_ACCEPT"
  }
 ],
 "capabilities": [],
 "tags": []
}

Because of the bug, host AA:AA:AA:AA:AA is not filtered.

The following JSON should work though:

{
 "rules": [
  {
   "type": "MATCH_MAC_SOURCE",
   "not": false,
   "or": false,
   "mac": "aaaaaaaaaa"
  },
  {
   "type": "ACTION_DROP"
  },
  {
   "type": "ACTION_ACCEPT"
  }
 ],
 "capabilities": [],
 "tags": []
}

lel-amri avatar Nov 15 '23 17:11 lel-amri

Unfortunately I don't think I can merge this because the result of cleanMac (which is void) was being passed to the constructor of std::string which cannot work. I've pulled your changes from your fork and made a new branch with additional fixes. We still need to do a proper end-to-end test.

Closing this PR.

joseph-henry avatar Mar 05 '24 20:03 joseph-henry

Thanks for working on this :) Indeed I overlooked that, and I did not run the code. Also, maybe doing the operation in-place is not a good design, I'm not sure.

lel-amri avatar Mar 05 '24 20:03 lel-amri

Thanks for the effort and we can still work on merging in your change with the extra fix on the other branch. Feel free to test it.

joseph-henry avatar Mar 05 '24 20:03 joseph-henry