logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

networkd.lua (4137B)


  1. -- Copyright 2016-2024 Christian Hesse. See LICENSE.
  2. -- systemd networkd file LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('networkd', {lex_by_line = true})
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  11. -- Boolean values.
  12. 'true', 'false', 'on', 'off', 'yes', 'no'
  13. }))
  14. -- Options.
  15. lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{
  16. -- Match section.
  17. 'MACAddress', 'OriginalName', 'Path', 'Driver', 'Type', 'Host', 'Name', 'Virtualization',
  18. 'KernelCommandLine', 'Architecture',
  19. -- Link section.
  20. 'Description', 'Alias', 'MACAddressPolicy', 'MACAddress', 'NamePolicy', 'Name', 'MTUBytes',
  21. 'BitsPerSecond', 'Duplex', 'WakeOnLan',
  22. -- Network section.
  23. 'Description', 'DHCP', 'DHCPServer', 'LinkLocalAddressing', 'IPv4LLRoute', 'IPv6Token', 'LLMNR',
  24. 'MulticastDNS', 'DNSSEC', 'DNSSECNegativeTrustAnchors', 'LLDP', 'BindCarrier', 'Address',
  25. 'Gateway', 'DNS', 'Domains', 'NTP', 'IPForward', 'IPMasquerade', 'IPv6PrivacyExtensions',
  26. 'IPv6AcceptRouterAdvertisements', 'IPv6DuplicateAddressDetection', 'IPv6HopLimit', 'Bridge',
  27. 'Bond', 'VLAN', 'MACVLAN', 'VXLAN', 'Tunnel',
  28. -- Address section.
  29. 'Address', 'Peer', 'Broadcast', 'Label',
  30. -- Route section.
  31. 'Gateway', 'Destination', 'Source', 'Metric', 'Scope', 'PreferredSource',
  32. -- DHCP section.
  33. 'UseDNS', 'UseNTP', 'UseMTU', 'SendHostname', 'UseHostname', 'Hostname', 'UseDomains',
  34. 'UseRoutes', 'UseTimezone', 'CriticalConnection', 'ClientIdentifier', 'VendorClassIdentifier',
  35. 'RequestBroadcast', 'RouteMetric',
  36. -- DHCPServer section.
  37. 'PoolOffset', 'PoolSize', 'DefaultLeaseTimeSec', 'MaxLeaseTimeSec', 'EmitDNS', 'DNS', 'EmitNTP',
  38. 'NTP', 'EmitTimezone', 'Timezone',
  39. -- Bridge section.
  40. 'UnicastFlood', 'HairPin', 'UseBPDU', 'FastLeave', 'AllowPortToBeRoot', 'Cost',
  41. -- BridgeFDP section.
  42. 'MACAddress', 'VLANId',
  43. -- NetDev section.
  44. 'Description', 'Name', 'Kind', 'MTUBytes', 'MACAddress',
  45. -- Bridge (netdev) section.
  46. 'HelloTimeSec', 'MaxAgeSec', 'ForwardDelaySec',
  47. -- VLAN section.
  48. 'Id',
  49. -- MACVLAN MACVTAP and IPVLAN section.
  50. 'Mode',
  51. -- VXLAN section.
  52. 'Id', 'Group', 'TOS', 'TTL', 'MacLearning', 'FDBAgeingSec', 'MaximumFDBEntries', 'ARPProxy',
  53. 'L2MissNotification', 'L3MissNotification', 'RouteShortCircuit', 'UDPCheckSum',
  54. 'UDP6ZeroChecksumTx', 'UDP6ZeroCheckSumRx', 'GroupPolicyExtension', 'DestinationPort',
  55. 'PortRange',
  56. -- Tunnel section.
  57. 'Local', 'Remote', 'TOS', 'TTL', 'DiscoverPathMTU', 'IPv6FlowLabel', 'CopyDSCP',
  58. 'EncapsulationLimit', 'Mode',
  59. -- Peer section.
  60. 'Name', 'MACAddress',
  61. -- Tun and Tap section.
  62. 'OneQueue', 'MultiQueue', 'PacketInfo', 'VNetHeader', 'User', 'Group',
  63. -- Bond section.
  64. 'Mode', 'TransmitHashPolicy', 'LACPTransmitRate', 'MIIMonitorSec', 'UpDelaySec', 'DownDelaySec',
  65. 'LearnPacketIntervalSec', 'AdSelect', 'FailOverMACPolicy', 'ARPValidate', 'ARPIntervalSec',
  66. 'ARPIPTargets', 'ARPAllTargets', 'PrimaryReselectPolicy', 'ResendIGMP', 'PacketsPerSlave',
  67. 'GratuitousARP', 'AllSlavesActive', 'MinLinks'
  68. }))
  69. -- Identifiers.
  70. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
  71. -- Strings.
  72. local sq_str = lexer.range("'")
  73. local dq_str = lexer.range('"')
  74. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  75. -- Sections.
  76. lex:add_rule('section', token(lexer.LABEL, '[' * word_match{
  77. 'Address', 'Link', 'Match', 'Network', 'Route', 'DHCP', 'DHCPServer', 'Bridge', 'BridgeFDB',
  78. 'NetDev', 'VLAN', 'MACVLAN', 'MACVTAP', 'IPVLAN', 'VXLAN', 'Tunnel', 'Peer', 'Tun', 'Tap', 'Bond'
  79. } * ']'))
  80. -- Comments.
  81. lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#')))))
  82. -- Numbers.
  83. local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
  84. lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer))
  85. -- Operators.
  86. lex:add_rule('operator', token(lexer.OPERATOR, '='))
  87. lexer.property['scintillua.comment'] = '#'
  88. return lex