Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 0x4A6F-master
  • 0x4A6F-rpi4
  • autinerd/experimental-openwrt-24.10
  • experimental
  • feature/addMikrotikwAP
  • master
  • nrb/airmax-test
  • nrb/ar9344-reset-sequence
  • nrb/ex400-remove-wps
  • nrb/gluon-master-cpe510
  • nrb/test-radv-filter
  • nrbffs/fastd-remove-delay
  • nrbffs/netgear-ex6120
  • v2018.2.2-ffs
  • v2018.2.3-ffs
  • v2019.1-ffs
  • v2019.1.1-ffs
  • v2019.1.2-ffs
  • v2020.1-ffs
  • v2020.1.1-ffs
  • v2020.1.3-ffs
  • v2020.2-ffs
  • v2020.2.1-ffs
  • v2020.2.2-ffs
  • v2020.2.3-ffs
  • v2021.1-ffs
  • v2021.1.1-ffs
  • v2021.1.2-ffs
  • v2022.1.1-ffs
  • v2022.1.3-ffs
  • v2022.1.4-ffs
  • v2023.1-ffs
  • v2023.2-ffs
  • v2023.2.2-ffs
  • v2023.2.3-ffs
  • v2023.2.4-ffs
  • v2023.2.5-ffs
  • experimental-2022-09-24
  • experimental-2022-09-24-base
  • experimental-2023-03-11
  • experimental-2023-03-11-base
  • experimental-2023-03-12
  • experimental-2023-03-12-base
  • experimental-2023-03-16
  • experimental-2023-03-16-base
  • experimental-2023-03-20
  • experimental-2023-03-20-base
  • experimental-2023-03-23
  • experimental-2023-03-23-base
  • experimental-2023-03-25
  • experimental-2023-03-25-base
  • experimental-2023-03-26
  • experimental-2023-03-26-base
  • experimental-2023-03-30
  • experimental-2023-03-30-base
  • experimental-2023-03-31
  • experimental-2023-03-31-base
  • experimental-2023-04-01
  • experimental-2023-04-01-base
  • experimental-2023-04-08
  • experimental-2023-04-08-base
  • experimental-2023-04-10
  • experimental-2023-04-10-base
  • experimental-2023-04-13
  • experimental-2023-04-13-base
  • experimental-2023-04-15
  • experimental-2023-04-15-base
  • experimental-2023-04-16
  • experimental-2023-04-16-base
  • experimental-2023-04-18
  • experimental-2023-04-18-base
  • experimental-2023-04-20
  • experimental-2023-04-20-base
  • experimental-2023-04-26
  • experimental-2023-04-26-base
  • experimental-2023-04-28
  • experimental-2023-04-28-base
  • experimental-2023-04-30
  • experimental-2023-04-30-base
  • experimental-2023-05-02
  • experimental-2023-05-02-base
  • experimental-2023-05-03
  • experimental-2023-05-03-base
  • experimental-2023-05-12
  • experimental-2023-05-12-base
  • experimental-2023-05-21
  • experimental-2023-05-21-base
  • experimental-2023-05-25
  • experimental-2023-05-25-base
  • experimental-2023-07-02
  • experimental-2023-07-02-base
  • experimental-2023-07-04
  • experimental-2023-07-04-base
  • experimental-2023-07-12
  • experimental-2023-07-12-base
  • experimental-2023-07-16
  • experimental-2023-07-16-base
  • experimental-2023-08-04
  • experimental-2023-08-04-base
  • experimental-2023-08-10
  • experimental-2023-08-10-base
  • experimental-2023-09-08
  • experimental-2023-09-08-base
  • experimental-2023-09-09
  • experimental-2023-09-09-base
  • experimental-2023-09-10
  • experimental-2023-09-10-base
  • experimental-2023-09-11
  • experimental-2023-09-11-base
  • experimental-2023-09-12
  • experimental-2023-09-12-base
  • experimental-2023-09-13
  • experimental-2023-09-13-base
  • experimental-2023-09-15
  • experimental-2023-09-15-base
  • experimental-2023-09-16
  • experimental-2023-09-16-base
  • experimental-2023-09-18
  • experimental-2023-09-18-base
  • experimental-2023-09-20
  • experimental-2023-09-20-base
  • experimental-2023-09-27
  • experimental-2023-09-27-base
  • experimental-2023-09-28
  • experimental-2023-09-28-base
  • experimental-2023-09-29
  • experimental-2023-09-29-base
  • experimental-2023-10-02
  • experimental-2023-10-02-base
  • experimental-2023-10-13
  • experimental-2023-10-13-base
  • experimental-2023-10-14
  • experimental-2023-10-14-base
  • experimental-2023-10-16
  • experimental-2023-10-16-base
  • experimental-2023-10-23
  • experimental-2023-10-23-base
137 results

Target

Select target project
  • firmware/gluon
  • 0x4A6F/gluon
  • patrick/gluon
3 results
Select Git revision
  • 0x4A6F-master
  • 0x4A6F-rpi4
  • 2014.3.x
  • 2014.4.x
  • babel
  • experimental
  • hoodselector
  • master
  • nrb/gluon-master-cpe510
  • nrb/test-radv-filter
  • nrbffs/fastd-remove-delay
  • nrbffs/netgear-ex6120
  • radv-filterd
  • v2015.1.x
  • v2016.1.x
  • v2016.2.4-batmanbug
  • v2016.2.x
  • v2018.2.2-ffs
  • v2018.2.3-ffs
  • v2018.2.x
  • v2019.1-ffs
  • v2019.1.1-ffs
  • v2019.1.2-ffs
  • v2020.1-ffs
  • v2020.1.1-ffs
  • v2020.1.3-ffs
  • v2020.2-ffs
  • v2020.2.1-ffs
  • v2020.2.2-ffs
  • v2020.2.3-ffs
  • v2020.2.x
  • v2021.1-ffs
  • v2021.1.1-ffs
  • v2021.1.2-ffs
  • v2014.1
  • v2014.2
  • v2014.3
  • v2014.3.1
  • v2014.4
  • v2015.1
  • v2015.1.1
  • v2015.1.2
  • v2016.1
  • v2016.1.1
  • v2016.1.2
  • v2016.1.3
  • v2016.1.4
  • v2016.1.5
  • v2016.1.6
  • v2016.2
  • v2016.2.1
  • v2016.2.2
  • v2016.2.3
  • v2016.2.4
  • v2016.2.5
  • v2016.2.6
  • v2016.2.7
  • v2017.1
  • v2017.1.1
  • v2017.1.2
  • v2017.1.3
  • v2017.1.4
  • v2017.1.5
  • v2017.1.6
  • v2017.1.7
  • v2017.1.8
  • v2018.1
  • v2018.1.1
  • v2018.1.2
  • v2018.1.3
  • v2018.1.4
  • v2018.2
  • v2018.2-ffs0.1
  • v2018.2.1
  • v2018.2.1-ffs0.1
  • v2018.2.2-ffs0.1
  • v2018.2.3-ffs0.1
  • v2019.1-ffs0.1
  • v2019.1.1-ffs0.1
  • v2019.1.2-ffs0.1
  • v2020.1-ffs0.1
  • v2020.1.1-ffs0.1
  • v2020.1.3-ffs0.1
  • v2020.2
  • v2020.2-ffs0.1
  • v2020.2.1-ffs0.1
  • v2020.2.2-ffs0.1
  • v2020.2.3-ffs0.1
  • v2020.2.3-ffs0.2
  • v2020.2.3-ffs0.3
  • v2020.2.x-ffs0.1
  • v2021.1-ffs0.1
  • v2021.1.1-ffs0.1
  • v2021.1.1-ffs0.2
  • v2021.1.1-ffs0.3
  • v2021.1.1-ffs0.4
  • v2021.1.2-ffs0.1
  • v2021.1.2-ffs0.2
98 results
Show changes
Showing
with 1089 additions and 283 deletions
......@@ -2,17 +2,15 @@
-- Copyright 2017 Matthias Schiffer <mschiffer@universe-factory.net>
-- Licensed to the public under the Apache License 2.0.
local string = string
local table = table
local protocol = require "gluon.web.http.protocol"
local util = require "gluon.web.util"
local ipairs, pairs, tostring = ipairs, pairs, tostring
module "gluon.web.http"
local M = {}
local Http = util.class()
M.Http = Http
Http = util.class()
function Http:__init__(env, input, output)
self.input = input
self.output = output
......@@ -55,8 +53,8 @@ end
function Http:getcookie(name)
local c = string.gsub(";" .. (self:getenv("HTTP_COOKIE") or "") .. ";", "%s*;%s*", ";")
local p = ";" .. name .. "=(.-);"
local i, j, value = c:find(p)
return value and urldecode(value)
local _, _, value = c:find(p)
return value and protocol.urldecode(value)
end
function Http:getenv(name)
......@@ -80,13 +78,6 @@ end
function Http:prepare_content(mime)
if self.headers["content-type"] then return end
if mime == "application/xhtml+xml" then
local accept = self:getenv("HTTP_ACCEPT")
if not accept or not accept:find("application/xhtml+xml", nil, true) then
mime = "text/html; charset=UTF-8"
end
self:header("Vary", "Accept")
end
self:header("Content-Type", mime)
end
......@@ -120,3 +111,5 @@ function Http:redirect(url)
self:header("Location", url)
self:close()
end
return M
......@@ -3,12 +3,9 @@
-- Licensed to the public under the Apache License 2.0.
-- This class contains several functions useful for http message- and content
-- decoding and to retrive form data from raw http messages.
module("gluon.web.http.protocol", package.seeall)
HTTP_MAX_CONTENT = 1024*8 -- 8 kB maximum content size
-- decoding and to retrieve form data from raw http messages.
local M = {}
local function pump(src, snk)
while true do
......@@ -26,7 +23,7 @@ local function pump(src, snk)
end
end
function urlencode(s)
function M.urlencode(s)
return (string.gsub(s, '[^a-zA-Z0-9%-_%.~]',
function(c)
local ret = ''
......@@ -41,7 +38,7 @@ function urlencode(s)
end
-- the "+" sign to " " - and return the decoded string.
function urldecode(str, no_plus)
function M.urldecode(str, no_plus)
local function chrdec(hex)
return string.char(tonumber(hex, 16))
......@@ -75,7 +72,7 @@ end
-- Simple parameters are stored as string values associated with the parameter
-- name within the table. Parameters with multiple values are stored as array
-- containing the corresponding values.
function urldecode_params(url)
function M.urldecode_params(url)
local params = {}
if url:find("?") then
......@@ -85,8 +82,8 @@ function urldecode_params(url)
for pair in url:gmatch("[^&;]+") do
-- find key and value
local key = urldecode(pair:match("^([^=]+)"))
local val = urldecode(pair:match("^[^=]+=(.+)$"))
local key = M.urldecode(pair:match("^([^=]+)"))
local val = M.urldecode(pair:match("^[^=]+=(.+)$"))
-- store
if key and key:len() > 0 then
......@@ -101,39 +98,34 @@ function urldecode_params(url)
end
-- Content-Type. Stores all extracted data associated with its parameter name
-- in the params table withing the given message object. Multiple parameter
-- in the params table within the given message object. Multiple parameter
-- values are stored as tables, ordinary ones as strings.
-- If an optional file callback function is given then it is feeded with the
-- If an optional file callback function is given then it is fed with the
-- file contents chunk by chunk and only the extracted file name is stored
-- within the params table. The callback function will be called subsequently
-- with three arguments:
-- o Table containing decoded (name, file) and raw (headers) mime header data
-- o String value containing a chunk of the file data
-- o Boolean which indicates wheather the current chunk is the last one (eof)
function mimedecode_message_body(src, msg, filecb)
if msg and msg.env.CONTENT_TYPE then
msg.mime_boundary = msg.env.CONTENT_TYPE:match("^multipart/form%-data; boundary=(.+)$")
-- o Boolean which indicates whether the current chunk is the last one (eof)
local function mimedecode_message_body(src, msg, filecb)
local mime_boundary = (msg.env.CONTENT_TYPE or ''):match("^multipart/form%-data; boundary=(.+)$")
if not mime_boundary then
error("Invalid Content-Type found")
end
if not msg.mime_boundary then
return nil, "Invalid Content-Type found"
end
local tlen = 0
local inhdr = false
local field = nil
local store = nil
local lchunk = nil
local function parse_headers(chunk, field)
local function parse_headers(chunk, pfield)
local stat
repeat
chunk, stat = chunk:gsub(
"^([A-Z][A-Za-z0-9%-_]+): +([^\r\n]+)\r\n",
function(k,v)
field.headers[k] = v
pfield.headers[k] = v
return ""
end
)
......@@ -143,26 +135,26 @@ function mimedecode_message_body(src, msg, filecb)
-- End of headers
if stat > 0 then
if field.headers["Content-Disposition"] then
if field.headers["Content-Disposition"]:match("^form%-data; ") then
field.name = field.headers["Content-Disposition"]:match('name="(.-)"')
field.file = field.headers["Content-Disposition"]:match('filename="(.+)"$')
if pfield.headers["Content-Disposition"] then
if pfield.headers["Content-Disposition"]:match("^form%-data; ") then
pfield.name = pfield.headers["Content-Disposition"]:match('name="(.-)"')
pfield.file = pfield.headers["Content-Disposition"]:match('filename="(.+)"$')
end
end
if not field.headers["Content-Type"] then
field.headers["Content-Type"] = "text/plain"
if not pfield.headers["Content-Type"] then
pfield.headers["Content-Type"] = "text/plain"
end
if field.name then
initval(msg.params, field.name)
if field.file then
appendval(msg.params, field.name, field.file)
if pfield.name then
initval(msg.params, pfield.name)
if pfield.file then
appendval(msg.params, pfield.name, pfield.file)
store = filecb
else
store = function(hdr, buf, eof)
appendval(msg.params, field.name, buf)
store = function(_, buf, _)
appendval(msg.params, pfield.name, buf)
end
end
else
......@@ -191,15 +183,16 @@ function mimedecode_message_body(src, msg, filecb)
local spos, epos, found
repeat
spos, epos = data:find("\r\n--" .. msg.mime_boundary .. "\r\n", 1, true)
spos, epos = data:find("\r\n--" .. mime_boundary .. "\r\n", 1, true)
if not spos then
spos, epos = data:find("\r\n--" .. msg.mime_boundary .. "--\r\n", 1, true)
spos, epos = data:find("\r\n--" .. mime_boundary .. "--\r\n", 1, true)
end
if spos then
local predata = data:sub(1, spos - 1)
local eof
if inhdr then
predata, eof = parse_headers(predata, field)
......@@ -228,11 +221,12 @@ function mimedecode_message_body(src, msg, filecb)
-- We found at least some boundary. Save
-- the unparsed remaining data for the
-- next chunk.
lchunk, data = data, nil
lchunk = data
else
-- There was a complete chunk without a boundary. Parse it as headers or
-- append it as data, depending on our current state.
if inhdr then
local eof
lchunk, eof = parse_headers(data, field)
inhdr = not eof
else
......@@ -243,7 +237,7 @@ function mimedecode_message_body(src, msg, filecb)
if store then
store(field, lchunk, false)
end
lchunk, chunk = chunk, nil
lchunk = chunk
end
end
end
......@@ -251,18 +245,61 @@ function mimedecode_message_body(src, msg, filecb)
return true
end
return pump(src, snk)
assert(pump(src, snk))
end
local function check_post_origin(msg)
local default_port = '80'
local request_scheme = 'http'
if msg.env.HTTPS then
default_port = '443'
request_scheme = 'https'
end
local request_host = msg.env.HTTP_HOST
if not request_host then
error('POST request without Host header')
end
if not request_host:match(':[0-9]+$') then
request_host = request_host .. ':' .. default_port
end
local origin = msg.env.HTTP_ORIGIN
if not origin then
error('POST request without Origin header')
end
local origin_scheme, origin_host = origin:match('^([^:]*)://(.*)$')
if not origin_host then
error('POST request with invalid Origin header')
end
if not origin_host:match(':[0-9]+$') then
local origin_port
if origin_scheme == 'http' then
origin_port = '80'
elseif origin_scheme == 'https' then
origin_port = '443'
else
error('POST request with invalid Origin header')
end
origin_host = origin_host .. ':' .. origin_port
end
if request_scheme ~= origin_scheme or request_host ~= origin_host then
error('Invalid cross-origin POST')
end
end
-- This function will examine the Content-Type within the given message object
-- to select the appropriate content decoder.
-- Currently only the multipart/form-data mime type is supported.
function parse_message_body(src, msg, filecb)
if not (msg.env.REQUEST_METHOD == "POST" and msg.env.CONTENT_TYPE) then
function M.parse_message_body(src, msg, filecb)
if msg.env.REQUEST_METHOD ~= "POST" then
return
end
if msg.env.CONTENT_TYPE:match("^multipart/form%-data") then
return mimedecode_message_body(src, msg, filecb)
end
check_post_origin(msg)
mimedecode_message_body(src, msg, filecb)
end
return M
......@@ -13,7 +13,7 @@ return function(config)
return string.format('%s/%s.%s.lmo', i18ndir, pkg, lang)
end
local function no_translation(key)
local function no_translation()
return nil
end
......
......@@ -44,13 +44,13 @@ return function(config, env)
translate = t.translate,
translatef = t.translatef,
_translate = t._translate,
include = function(name)
ctx.render(name, scope, pkg)
include = function(include_name)
ctx.render(include_name, scope, pkg)
end,
}
setfenv(template, setmetatable({}, {
__index = function(tbl, key)
__index = function(_, key)
return scope[key] or locals[key] or env[key]
end
}))
......@@ -58,7 +58,7 @@ return function(config, env)
-- Now finally render the thing
local stat, err = pcall(template)
assert(stat, "Failed to execute template '" .. name .. "'.\n" ..
"A runtime error occured: " .. tostring(err or "(nil)"))
"A runtime error occurred: " .. tostring(err or "(nil)"))
end
--- Render a certain template.
......
......@@ -4,10 +4,8 @@
local tparser = require "gluon.web.template.parser"
local getmetatable, setmetatable = getmetatable, setmetatable
local tostring = tostring
module "gluon.web.util"
local M = {}
--
-- Class helper routines
......@@ -33,14 +31,14 @@ end
-- to the __init__ function of this class - if such a function exists.
-- The __init__ function must be used to set any object parameters that are not shared
-- with other objects of this class. Any return values will be ignored.
function class(base)
function M.class(base)
return setmetatable({}, {
__call = _instantiate,
__index = base
})
end
function instanceof(object, class)
function M.instanceof(object, class)
while object do
if object == class then
return true
......@@ -56,6 +54,8 @@ end
-- String and data manipulation routines
--
function pcdata(value)
function M.pcdata(value)
return value and tparser.pcdata(tostring(value))
end
return M
......@@ -9,6 +9,8 @@ clean:
parser.so: template_parser.o template_utils.o template_lmo.o template_lualib.o
$(CC) $(LDFLAGS) -shared -o $@ $^
gluon-po2lmo: gluon-po2lmo.o template_lmo.o
compile: parser.so
install: compile
......
/*
* lmo - Lua Machine Objects - PO to LMO conversion tool
*
* Copyright (C) 2009-2012 Jo-Philipp Wich <jow@openwrt.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "template_lmo.h"
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
__attribute__((noreturn))
static void die(const char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
exit(1);
}
__attribute__((noreturn))
static void usage(const char *name)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
exit(1);
}
static void print(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
if( fwrite(ptr, size, nmemb, stream) == 0 )
die("Failed to write stdout");
}
static ssize_t extract_string(const char *src, char *dest, size_t len)
{
size_t pos = 0;
int esc = 0;
int off = -1;
for( pos = 0; (pos < strlen(src)) && (pos < len); pos++ )
{
if( (off == -1) && (src[pos] == '"') )
{
off = pos + 1;
}
else if( off >= 0 )
{
if( esc == 1 )
{
switch (src[pos])
{
case '"':
case '\\':
off++;
break;
}
dest[pos-off] = src[pos];
esc = 0;
}
else if( src[pos] == '\\' )
{
dest[pos-off] = src[pos];
esc = 1;
}
else if( src[pos] != '"' )
{
dest[pos-off] = src[pos];
}
else
{
dest[pos-off] = '\0';
break;
}
}
}
return (off > -1) ? (ssize_t) strlen(dest) : -1;
}
static int cmp_index(const void *a, const void *b)
{
uint32_t x = ((const lmo_entry_t *)a)->key_id;
uint32_t y = ((const lmo_entry_t *)b)->key_id;
if (x < y)
return -1;
else if (x > y)
return 1;
return 0;
}
static void print_uint32(uint32_t x, FILE *out)
{
uint32_t y = htonl(x);
print(&y, sizeof(uint32_t), 1, out);
}
static void print_index(void *array, int n, FILE *out)
{
lmo_entry_t *e;
qsort(array, n, sizeof(*e), cmp_index);
for (e = array; n > 0; n--, e++)
{
print_uint32(e->key_id, out);
print_uint32(e->val_id, out);
print_uint32(e->offset, out);
print_uint32(e->length, out);
}
}
int main(int argc, char *argv[])
{
char line[4096];
char key[4096];
char val[4096];
char tmp[4096];
int state = 0;
int offset = 0;
int length = 0;
int n_entries = 0;
void *array = NULL;
lmo_entry_t *entry = NULL;
uint32_t key_id, val_id;
FILE *in;
FILE *out;
if( (argc != 3) || ((in = fopen(argv[1], "r")) == NULL) || ((out = fopen(argv[2], "w")) == NULL) )
usage(argv[0]);
memset(line, 0, sizeof(key));
memset(key, 0, sizeof(val));
memset(val, 0, sizeof(val));
while( (NULL != fgets(line, sizeof(line), in)) || (state >= 2 && feof(in)) )
{
if( state == 0 && strstr(line, "msgid \"") == line )
{
switch(extract_string(line, key, sizeof(key)))
{
case -1:
die("Syntax error in msgid");
case 0:
state = 1;
break;
default:
state = 2;
}
}
else if( state == 1 || state == 2 )
{
if( strstr(line, "msgstr \"") == line || state == 2 )
{
switch(extract_string(line, val, sizeof(val)))
{
case -1:
state = 4;
break;
default:
state = 3;
}
}
else
{
switch(extract_string(line, tmp, sizeof(tmp)))
{
case -1:
state = 2;
break;
default:
strcat(key, tmp);
}
}
}
else if( state == 3 )
{
switch(extract_string(line, tmp, sizeof(tmp)))
{
case -1:
state = 4;
break;
default:
strcat(val, tmp);
}
}
if( state == 4 )
{
if( strlen(key) > 0 && strlen(val) > 0 )
{
key_id = sfh_hash(key, strlen(key));
val_id = sfh_hash(val, strlen(val));
if( key_id != val_id )
{
n_entries++;
array = realloc(array, n_entries * sizeof(lmo_entry_t));
entry = (lmo_entry_t *)array + n_entries - 1;
if (!array)
die("Out of memory");
entry->key_id = key_id;
entry->val_id = val_id;
entry->offset = offset;
entry->length = strlen(val);
length = strlen(val) + ((4 - (strlen(val) % 4)) % 4);
print(val, length, 1, out);
offset += length;
}
}
state = 0;
memset(key, 0, sizeof(key));
memset(val, 0, sizeof(val));
}
memset(line, 0, sizeof(line));
}
print_index(array, n_entries, out);
if( offset > 0 )
{
print_uint32(offset, out);
fsync(fileno(out));
fclose(out);
}
else
{
fclose(out);
unlink(argv[2]);
}
fclose(in);
return(0);
}
......@@ -25,20 +25,11 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
struct lmo_entry {
uint32_t key_id;
uint32_t val_id;
uint32_t offset;
uint32_t length;
} __attribute__((packed));
static inline uint16_t get_le16(const void *data) {
const uint8_t *d = data;
return (((uint16_t)d[1]) << 8) | d[0];
......@@ -56,7 +47,7 @@ static inline uint32_t get_be32(const void *data) {
* Hash function from http://www.azillionmonkeys.com/qed/hash.html
* Copyright (C) 2004-2008 by Paul Hsieh
*/
static uint32_t sfh_hash(const void *input, size_t len)
uint32_t sfh_hash(const void *input, size_t len)
{
const uint8_t *data = input;
uint32_t hash = len, tmp;
......
......@@ -22,8 +22,15 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct lmo_entry {
uint32_t key_id;
uint32_t val_id;
uint32_t offset;
uint32_t length;
} __attribute__((packed));
typedef struct lmo_entry lmo_entry_t;
......@@ -37,6 +44,8 @@ struct lmo_catalog {
typedef struct lmo_catalog lmo_catalog_t;
uint32_t sfh_hash(const void *input, size_t len);
bool lmo_load(lmo_catalog_t *cat, const char *file);
void lmo_unload(lmo_catalog_t *cat);
bool lmo_translate(const lmo_catalog_t *cat, const char *key, size_t keylen, const char **out, size_t *outlen);
......
......@@ -235,7 +235,7 @@ static size_t validate_utf8(const unsigned char **s, size_t l, struct template_b
break;
}
/* advance beyound the last found valid continuation char */
/* advance beyond the last found valid continuation char */
o = v;
ptr += v;
}
......
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-wireless-encryption-wpa3
include ../gluon.mk
define Package/gluon-wireless-encryption-wpa3
DEPENDS:=+hostapd-mbedtls
TITLE:=Package for supporting WPA3 encrypted wireless networks
endef
define Package/gluon-wireless-encryption-wpa3/install
$(INSTALL_DIR) $(1)/lib/gluon/features
touch $(1)/lib/gluon/features/wpa2
touch $(1)/lib/gluon/features/wpa3
endef
$(eval $(call BuildPackageGluon,gluon-wireless-encryption-wpa3))
GLUON_MK := $(abspath $(lastword $(MAKEFILE_LIST)))
PKG_FILE_DEPENDS += $(GLUON_MK)
# Dependencies for LuaSrcDiet
PKG_BUILD_DEPENDS += luci-base/host
PKG_VERSION ?= 1
PKG_BUILD_DEPENDS += luasrcdiet/host
ifneq ($(wildcard ./luasrc/.),)
PKG_CONFIG_DEPENDS += CONFIG_GLUON_MINIFY
endif
ifneq ($(wildcard ./src/respondd.c),)
PKG_BUILD_DEPENDS += respondd
......@@ -18,7 +23,8 @@ shell-verbatim = $(call shell-unescape,$(call shell-escape,$(1)))
define GluonCheckSite
[ -z "$$IPKG_INSTROOT" ] || "${TOPDIR}/staging_dir/hostpkg/bin/lua" "${TOPDIR}/../scripts/check_site.lua" <<'END__GLUON__CHECK__SITE'
[ -z "$$STAGING_DIR_HOSTPKG" ] || PATH="$$STAGING_DIR_HOSTPKG/bin:$$PATH"
lua "$$IPKG_INSTROOT/lib/gluon/check-site.lua" <<'END__GLUON__CHECK__SITE'
$(call shell-verbatim,cat '$(1)')
END__GLUON__CHECK__SITE
endef
......@@ -31,6 +37,7 @@ GLUON_I18N_CONFIG := $(foreach lang,$(GLUON_SUPPORTED_LANGS),CONFIG_GLUON_WEB_LA
GLUON_ENABLED_LANGS := en $(foreach lang,$(GLUON_SUPPORTED_LANGS),$(if $(CONFIG_GLUON_WEB_LANG_$(lang)),$(lang)))
ifneq ($(wildcard ./i18n/.),)
PKG_BUILD_DEPENDS += gluon-web/host
PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
endif
......@@ -40,7 +47,7 @@ define GluonBuildI18N
for lang in $$(GLUON_ENABLED_LANGS); do \
if [ -e $(1)/$$$$lang.po ]; then \
rm -f $$(PKG_BUILD_DIR)/i18n/$$$$lang.lmo; \
po2lmo $(1)/$$$$lang.po $$(PKG_BUILD_DIR)/i18n/$$$$lang.lmo; \
gluon-po2lmo $(1)/$$$$lang.po $$(PKG_BUILD_DIR)/i18n/$$$$lang.lmo; \
fi; \
done
endef
......@@ -57,12 +64,15 @@ endef
define GluonSrcDiet
rm -rf $(2)
$(CP) $(1) $(2)
$(FIND) $(2) -type f | while read src; do \
if LuaSrcDiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; then \
chmod $$$$(stat -c%a "$$$$src") "$$$$src.o"; \
mv "$$$$src.o" "$$$$src"; \
fi; \
ifdef CONFIG_GLUON_MINIFY
# Use cp + rm instead of mv to preserve destination permissions
set -e; $(FIND) $(2) -type f | while read src; do \
echo "Minifying $$$$src..."; \
luasrcdiet --noopt-binequiv -o "$$$$src.tmp" "$$$$src"; \
cp "$$$$src.tmp" "$$$$src"; \
rm "$$$$src.tmp"; \
done
endif
endef
......
......@@ -41,58 +41,206 @@
__attribute__ ((visibility ("default")))
struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = {
[BATADV_ATTR_VERSION] = { .type = NLA_STRING },
[BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
[BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
[BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING,
.maxlen = IFNAMSIZ },
[BATADV_ATTR_MESH_ADDRESS] = { .type = NLA_UNSPEC,
[BATADV_ATTR_VERSION] = {
.type = NLA_STRING,
},
[BATADV_ATTR_ALGO_NAME] = {
.type = NLA_STRING,
},
[BATADV_ATTR_MESH_IFINDEX] = {
.type = NLA_U32,
},
[BATADV_ATTR_MESH_IFNAME] = {
.type = NLA_STRING,
.maxlen = IFNAMSIZ,
},
[BATADV_ATTR_MESH_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
[BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING,
.maxlen = IFNAMSIZ },
[BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_HARD_IFINDEX] = {
.type = NLA_U32,
},
[BATADV_ATTR_HARD_IFNAME] = {
.type = NLA_STRING,
.maxlen = IFNAMSIZ,
},
[BATADV_ATTR_HARD_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_ORIG_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
[BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
[BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
[BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
[BATADV_ATTR_PAD] = { .type = NLA_UNSPEC },
[BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
[BATADV_ATTR_TT_ADDRESS] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_TPMETER_RESULT] = {
.type = NLA_U8,
},
[BATADV_ATTR_TPMETER_TEST_TIME] = {
.type = NLA_U32,
},
[BATADV_ATTR_TPMETER_BYTES] = {
.type = NLA_U64,
},
[BATADV_ATTR_TPMETER_COOKIE] = {
.type = NLA_U32,
},
[BATADV_ATTR_PAD] = {
.type = NLA_UNSPEC,
},
[BATADV_ATTR_ACTIVE] = {
.type = NLA_FLAG,
},
[BATADV_ATTR_TT_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
[BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
[BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
[BATADV_ATTR_TT_VID] = { .type = NLA_U16 },
[BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 },
[BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
[BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
[BATADV_ATTR_NEIGH_ADDRESS] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_TT_TTVN] = {
.type = NLA_U8,
},
[BATADV_ATTR_TT_LAST_TTVN] = {
.type = NLA_U8,
},
[BATADV_ATTR_TT_CRC32] = {
.type = NLA_U32,
},
[BATADV_ATTR_TT_VID] = {
.type = NLA_U16,
},
[BATADV_ATTR_TT_FLAGS] = {
.type = NLA_U32,
},
[BATADV_ATTR_FLAG_BEST] = {
.type = NLA_FLAG,
},
[BATADV_ATTR_LAST_SEEN_MSECS] = {
.type = NLA_U32,
},
[BATADV_ATTR_NEIGH_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_TQ] = { .type = NLA_U8 },
[BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
[BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
[BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
[BATADV_ATTR_ROUTER] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_TQ] = {
.type = NLA_U8,
},
[BATADV_ATTR_THROUGHPUT] = {
.type = NLA_U32,
},
[BATADV_ATTR_BANDWIDTH_UP] = {
.type = NLA_U32,
},
[BATADV_ATTR_BANDWIDTH_DOWN] = {
.type = NLA_U32,
},
[BATADV_ATTR_ROUTER] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
[BATADV_ATTR_BLA_ADDRESS] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_BLA_OWN] = {
.type = NLA_FLAG,
},
[BATADV_ATTR_BLA_ADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
[BATADV_ATTR_BLA_BACKBONE] = { .type = NLA_UNSPEC,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_BLA_VID] = {
.type = NLA_U16,
},
[BATADV_ATTR_BLA_BACKBONE] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
[BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_BLA_CRC] = {
.type = NLA_U16,
},
[BATADV_ATTR_DAT_CACHE_IP4ADDRESS] = {
.type = NLA_U32,
},
[BATADV_ATTR_DAT_CACHE_HWADDRESS] = {
.type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN,
},
[BATADV_ATTR_DAT_CACHE_VID] = {
.type = NLA_U16,
},
[BATADV_ATTR_MCAST_FLAGS] = {
.type = NLA_U32,
},
[BATADV_ATTR_MCAST_FLAGS_PRIV] = {
.type = NLA_U32,
},
[BATADV_ATTR_VLANID] = {
.type = NLA_U16,
},
[BATADV_ATTR_AGGREGATED_OGMS_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_AP_ISOLATION_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_ISOLATION_MARK] = {
.type = NLA_U32,
},
[BATADV_ATTR_ISOLATION_MASK] = {
.type = NLA_U32,
},
[BATADV_ATTR_BONDING_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_FRAGMENTATION_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_GW_BANDWIDTH_DOWN] = {
.type = NLA_U32,
},
[BATADV_ATTR_GW_BANDWIDTH_UP] = {
.type = NLA_U32,
},
[BATADV_ATTR_GW_MODE] = {
.type = NLA_U8,
},
[BATADV_ATTR_GW_SEL_CLASS] = {
.type = NLA_U32,
},
[BATADV_ATTR_HOP_PENALTY] = {
.type = NLA_U8,
},
[BATADV_ATTR_LOG_LEVEL] = {
.type = NLA_U32,
},
[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_NETWORK_CODING_ENABLED] = {
.type = NLA_U8,
},
[BATADV_ATTR_ORIG_INTERVAL] = {
.type = NLA_U32,
},
[BATADV_ATTR_ELP_INTERVAL] = {
.type = NLA_U32,
},
[BATADV_ATTR_THROUGHPUT_OVERRIDE] = {
.type = NLA_U32,
},
[BATADV_ATTR_MULTICAST_FANOUT] = {
.type = NLA_U32,
},
};
/**
......
......@@ -79,10 +79,8 @@ struct batadv_nlquery_opts {
*
* Return: Return true when a attribute is missing, false otherwise
*/
static inline bool
batadv_genl_missing_attrs(struct nlattr *attrs[],
const enum batadv_nl_attrs mandatory[], size_t num)
{
static inline bool batadv_genl_missing_attrs(struct nlattr *attrs[],
const enum batadv_nl_attrs mandatory[], size_t num) {
size_t i;
for (i = 0; i < num; i++) {
......
/* SPDX-License-Identifier: MIT */
/* Copyright (C) 2016-2017 B.A.T.M.A.N. contributors:
/* Copyright (C) B.A.T.M.A.N. contributors:
*
* Matthias Schiffer
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef _UAPI_LINUX_BATMAN_ADV_H_
......@@ -27,6 +9,7 @@
#define BATADV_NL_NAME "batadv"
#define BATADV_NL_MCAST_GROUP_CONFIG "config"
#define BATADV_NL_MCAST_GROUP_TPMETER "tpmeter"
/**
......@@ -86,11 +69,72 @@ enum batadv_tt_client_flags {
/**
* @BATADV_TT_CLIENT_TEMP: this global client has been detected to be
* part of the network but no nnode has already announced it
* part of the network but no node has already announced it
*/
BATADV_TT_CLIENT_TEMP = (1 << 11),
};
/**
* enum batadv_mcast_flags_priv - Private, own multicast flags
*
* These are internal, multicast related flags. Currently they describe certain
* multicast related attributes of the segment this originator bridges into the
* mesh.
*
* Those attributes are used to determine the public multicast flags this
* originator is going to announce via TT.
*
* For netlink, if BATADV_MCAST_FLAGS_BRIDGED is unset then all querier
* related flags are undefined.
*/
enum batadv_mcast_flags_priv {
/**
* @BATADV_MCAST_FLAGS_BRIDGED: There is a bridge on top of the mesh
* interface.
*/
BATADV_MCAST_FLAGS_BRIDGED = (1 << 0),
/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS: Whether an IGMP querier
* exists in the mesh
*/
BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS = (1 << 1),
/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS: Whether an MLD querier
* exists in the mesh
*/
BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS = (1 << 2),
/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING: If an IGMP querier
* exists, whether it is potentially shadowing multicast listeners
* (i.e. querier is behind our own bridge segment)
*/
BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING = (1 << 3),
/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING: If an MLD querier
* exists, whether it is potentially shadowing multicast listeners
* (i.e. querier is behind our own bridge segment)
*/
BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING = (1 << 4),
};
/**
* enum batadv_gw_modes - gateway mode of node
*/
enum batadv_gw_modes {
/** @BATADV_GW_MODE_OFF: gw mode disabled */
BATADV_GW_MODE_OFF,
/** @BATADV_GW_MODE_CLIENT: send DHCP requests to gw servers */
BATADV_GW_MODE_CLIENT,
/** @BATADV_GW_MODE_SERVER: announce itself as gateway server */
BATADV_GW_MODE_SERVER,
};
/**
* enum batadv_nl_attrs - batman-adv netlink attributes
*/
......@@ -272,6 +316,171 @@ enum batadv_nl_attrs {
*/
BATADV_ATTR_BLA_CRC,
/**
* @BATADV_ATTR_DAT_CACHE_IP4ADDRESS: Client IPv4 address
*/
BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
/**
* @BATADV_ATTR_DAT_CACHE_HWADDRESS: Client MAC address
*/
BATADV_ATTR_DAT_CACHE_HWADDRESS,
/**
* @BATADV_ATTR_DAT_CACHE_VID: VLAN ID
*/
BATADV_ATTR_DAT_CACHE_VID,
/**
* @BATADV_ATTR_MCAST_FLAGS: Per originator multicast flags
*/
BATADV_ATTR_MCAST_FLAGS,
/**
* @BATADV_ATTR_MCAST_FLAGS_PRIV: Private, own multicast flags
*/
BATADV_ATTR_MCAST_FLAGS_PRIV,
/**
* @BATADV_ATTR_VLANID: VLAN id on top of soft interface
*/
BATADV_ATTR_VLANID,
/**
* @BATADV_ATTR_AGGREGATED_OGMS_ENABLED: whether the batman protocol
* messages of the mesh interface shall be aggregated or not.
*/
BATADV_ATTR_AGGREGATED_OGMS_ENABLED,
/**
* @BATADV_ATTR_AP_ISOLATION_ENABLED: whether the data traffic going
* from a wireless client to another wireless client will be silently
* dropped.
*/
BATADV_ATTR_AP_ISOLATION_ENABLED,
/**
* @BATADV_ATTR_ISOLATION_MARK: the isolation mark which is used to
* classify clients as "isolated" by the Extended Isolation feature.
*/
BATADV_ATTR_ISOLATION_MARK,
/**
* @BATADV_ATTR_ISOLATION_MASK: the isolation (bit)mask which is used to
* classify clients as "isolated" by the Extended Isolation feature.
*/
BATADV_ATTR_ISOLATION_MASK,
/**
* @BATADV_ATTR_BONDING_ENABLED: whether the data traffic going through
* the mesh will be sent using multiple interfaces at the same time.
*/
BATADV_ATTR_BONDING_ENABLED,
/**
* @BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED: whether the bridge loop
* avoidance feature is enabled. This feature detects and avoids loops
* between the mesh and devices bridged with the soft interface
*/
BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED,
/**
* @BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED: whether the distributed
* arp table feature is enabled. This feature uses a distributed hash
* table to answer ARP requests without flooding the request through
* the whole mesh.
*/
BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED,
/**
* @BATADV_ATTR_FRAGMENTATION_ENABLED: whether the data traffic going
* through the mesh will be fragmented or silently discarded if the
* packet size exceeds the outgoing interface MTU.
*/
BATADV_ATTR_FRAGMENTATION_ENABLED,
/**
* @BATADV_ATTR_GW_BANDWIDTH_DOWN: defines the download bandwidth which
* is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
* to 'server'.
*/
BATADV_ATTR_GW_BANDWIDTH_DOWN,
/**
* @BATADV_ATTR_GW_BANDWIDTH_UP: defines the upload bandwidth which
* is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
* to 'server'.
*/
BATADV_ATTR_GW_BANDWIDTH_UP,
/**
* @BATADV_ATTR_GW_MODE: defines the state of the gateway features.
* Possible values are specified in enum batadv_gw_modes
*/
BATADV_ATTR_GW_MODE,
/**
* @BATADV_ATTR_GW_SEL_CLASS: defines the selection criteria this node
* will use to choose a gateway if gw_mode was set to 'client'.
*/
BATADV_ATTR_GW_SEL_CLASS,
/**
* @BATADV_ATTR_HOP_PENALTY: defines the penalty which will be applied
* to an originator message's tq-field on every hop and/or per
* hard interface
*/
BATADV_ATTR_HOP_PENALTY,
/**
* @BATADV_ATTR_LOG_LEVEL: bitmask with to define which debug messages
* should be send to the debug log/trace ring buffer
*/
BATADV_ATTR_LOG_LEVEL,
/**
* @BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED: whether multicast
* optimizations should be replaced by simple broadcast-like flooding
* of multicast packets. If set to non-zero then all nodes in the mesh
* are going to use classic flooding for any multicast packet with no
* optimizations.
*/
BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED,
/**
* @BATADV_ATTR_NETWORK_CODING_ENABLED: whether Network Coding (using
* some magic to send fewer wifi packets but still the same content) is
* enabled or not.
*/
BATADV_ATTR_NETWORK_CODING_ENABLED,
/**
* @BATADV_ATTR_ORIG_INTERVAL: defines the interval in milliseconds in
* which batman sends its protocol messages.
*/
BATADV_ATTR_ORIG_INTERVAL,
/**
* @BATADV_ATTR_ELP_INTERVAL: defines the interval in milliseconds in
* which batman emits probing packets for neighbor sensing (ELP).
*/
BATADV_ATTR_ELP_INTERVAL,
/**
* @BATADV_ATTR_THROUGHPUT_OVERRIDE: defines the throughput value to be
* used by B.A.T.M.A.N. V when estimating the link throughput using
* this interface. If the value is set to 0 then batman-adv will try to
* estimate the throughput by itself.
*/
BATADV_ATTR_THROUGHPUT_OVERRIDE,
/**
* @BATADV_ATTR_MULTICAST_FANOUT: defines the maximum number of packet
* copies that may be generated for a multicast-to-unicast conversion.
* Once this limit is exceeded distribution will fall back to broadcast.
*/
BATADV_ATTR_MULTICAST_FANOUT,
/* add attributes above here, update the policy in netlink.c */
/**
......@@ -300,10 +509,14 @@ enum batadv_nl_commands {
BATADV_CMD_UNSPEC,
/**
* @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv
* device
* @BATADV_CMD_GET_MESH: Get attributes from softif/mesh
*/
BATADV_CMD_GET_MESH_INFO,
BATADV_CMD_GET_MESH,
/**
* @BATADV_CMD_GET_MESH_INFO: Alias for @BATADV_CMD_GET_MESH
*/
BATADV_CMD_GET_MESH_INFO = BATADV_CMD_GET_MESH,
/**
* @BATADV_CMD_TP_METER: Start a tp meter session
......@@ -321,9 +534,15 @@ enum batadv_nl_commands {
BATADV_CMD_GET_ROUTING_ALGOS,
/**
* @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces
* @BATADV_CMD_GET_HARDIF: Get attributes from a hardif of the
* current softif
*/
BATADV_CMD_GET_HARDIFS,
BATADV_CMD_GET_HARDIF,
/**
* @BATADV_CMD_GET_HARDIFS: Alias for @BATADV_CMD_GET_HARDIF
*/
BATADV_CMD_GET_HARDIFS = BATADV_CMD_GET_HARDIF,
/**
* @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations
......@@ -361,6 +580,39 @@ enum batadv_nl_commands {
*/
BATADV_CMD_GET_BLA_BACKBONE,
/**
* @BATADV_CMD_GET_DAT_CACHE: Query list of DAT cache entries
*/
BATADV_CMD_GET_DAT_CACHE,
/**
* @BATADV_CMD_GET_MCAST_FLAGS: Query list of multicast flags
*/
BATADV_CMD_GET_MCAST_FLAGS,
/**
* @BATADV_CMD_SET_MESH: Set attributes for softif/mesh
*/
BATADV_CMD_SET_MESH,
/**
* @BATADV_CMD_SET_HARDIF: Set attributes for hardif of the
* current softif
*/
BATADV_CMD_SET_HARDIF,
/**
* @BATADV_CMD_GET_VLAN: Get attributes from a VLAN of the
* current softif
*/
BATADV_CMD_GET_VLAN,
/**
* @BATADV_CMD_SET_VLAN: Set attributes for VLAN of the
* current softif
*/
BATADV_CMD_SET_VLAN,
/* add new commands above here */
/**
......@@ -423,4 +675,30 @@ enum batadv_tp_meter_reason {
BATADV_TP_REASON_TOO_MANY = 133,
};
/**
* enum batadv_ifla_attrs - batman-adv ifla nested attributes
*/
enum batadv_ifla_attrs {
/**
* @IFLA_BATADV_UNSPEC: unspecified attribute which is not parsed by
* rtnetlink
*/
IFLA_BATADV_UNSPEC,
/**
* @IFLA_BATADV_ALGO_NAME: routing algorithm (name) which should be
* used by the newly registered batadv net_device.
*/
IFLA_BATADV_ALGO_NAME,
/* add attributes above here, update the policy in soft-interface.c */
/**
* @__IFLA_BATADV_MAX: internal use
*/
__IFLA_BATADV_MAX,
};
#define IFLA_BATADV_MAX (__IFLA_BATADV_MAX - 1)
#endif /* _UAPI_LINUX_BATMAN_ADV_H_ */
/*
Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* SPDX-FileCopyrightText: 2016 Matthias Schiffer <mschiffer@universe-factory.net> */
/* SPDX-License-Identifier: BSD-2-Clause */
#include "libgluonutil.h"
#include <json-c/json.h>
#include <uci.h>
#include <arpa/inet.h>
#include <errno.h>
#include <glob.h>
#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
......@@ -127,6 +111,75 @@ char * gluonutil_get_interface_address(const char *ifname) {
return gluonutil_read_line(path);
}
void gluonutil_get_interface_lower(char out[IF_NAMESIZE], const char *ifname) {
strncpy(out, ifname, IF_NAMESIZE-1);
out[IF_NAMESIZE-1] = 0;
const char *format = "/sys/class/net/%s/lower_*";
char pattern[strlen(format) + IF_NAMESIZE];
while (true) {
snprintf(pattern, sizeof(pattern), format, out);
size_t pattern_len = strlen(pattern);
glob_t lower;
if (glob(pattern, GLOB_NOSORT, NULL, &lower) != 0)
break;
strncpy(out, lower.gl_pathv[0] + pattern_len - 1, IF_NAMESIZE-1);
globfree(&lower);
}
}
enum gluonutil_interface_type lookup_interface_type(const char *devtype) {
if (strcmp(devtype, "wlan") == 0)
return GLUONUTIL_INTERFACE_TYPE_WIRELESS;
if (strcmp(devtype, "l2tpeth") == 0 || strcmp(devtype, "wireguard") == 0)
return GLUONUTIL_INTERFACE_TYPE_TUNNEL;
/* Regular wired interfaces do not set DEVTYPE, so if this point is
* reached, we have something different */
return GLUONUTIL_INTERFACE_TYPE_UNKNOWN;
}
enum gluonutil_interface_type gluonutil_get_interface_type(const char *ifname) {
const char *pattern = "/sys/class/net/%s/%s";
/* Default to wired type when no DEVTYPE is set */
enum gluonutil_interface_type ret = GLUONUTIL_INTERFACE_TYPE_WIRED;
char *line = NULL, path[PATH_MAX];
size_t buflen = 0;
ssize_t len;
FILE *f;
snprintf(path, sizeof(path), pattern, ifname, "tun_flags");
if (access(path, F_OK) == 0)
return GLUONUTIL_INTERFACE_TYPE_TUNNEL;
snprintf(path, sizeof(path), pattern, ifname, "uevent");
f = fopen(path, "r");
if (!f)
return GLUONUTIL_INTERFACE_TYPE_UNKNOWN;
while ((len = getline(&line, &buflen, f)) >= 0) {
if (len == 0)
continue;
if (line[len-1] == '\n')
line[len-1] = '\0';
if (strncmp(line, "DEVTYPE=", 8) == 0) {
ret = lookup_interface_type(line+8);
break;
}
}
free(line);
fclose(f);
return ret;
}
struct json_object * gluonutil_wrap_string(const char *str) {
......@@ -212,6 +265,45 @@ uci_fail:
return ret;
}
char * gluonutil_get_primary_domain(void) {
if (!gluonutil_has_domains())
return NULL;
char *domain_code = gluonutil_get_domain();
if (!domain_code)
return NULL;
const char *domain_path_fmt = "/lib/gluon/domains/%s.json";
char domain_path[strlen(domain_path_fmt) + strlen(domain_code)];
snprintf(domain_path, sizeof(domain_path), domain_path_fmt, domain_code);
char primary_domain_path[PATH_MAX+1];
char *primary_domain_code;
ssize_t len = readlink(domain_path, primary_domain_path, PATH_MAX);
if (len < 0) {
// EINVAL = file is not a symlink = the domain itself is the primary domain
if (errno != EINVAL) {
free(domain_code);
return NULL;
}
return domain_code;
}
free(domain_code);
primary_domain_path[len] = '\0';
primary_domain_code = basename(primary_domain_path);
char *ext_begin = strrchr(primary_domain_code, '.');
if (!ext_begin)
return NULL;
// strip .json from filename
*ext_begin = '\0';
return strdup(primary_domain_code);
}
struct json_object * gluonutil_load_site_config(void) {
char *domain_code = NULL;
......@@ -243,6 +335,5 @@ struct json_object * gluonutil_load_site_config(void) {
err:
json_object_put(site);
free(domain_code);
return NULL;
}
/*
Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* SPDX-FileCopyrightText: 2016 Matthias Schiffer <mschiffer@universe-factory.net> */
/* SPDX-License-Identifier: BSD-2-Clause */
#ifndef _LIBGLUON_LIBGLUON_H_
#define _LIBGLUON_LIBGLUON_H_
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
......@@ -34,7 +13,18 @@
char * gluonutil_read_line(const char *filename);
char * gluonutil_get_sysconfig(const char *key);
char * gluonutil_get_node_id(void);
enum gluonutil_interface_type {
GLUONUTIL_INTERFACE_TYPE_UNKNOWN,
GLUONUTIL_INTERFACE_TYPE_WIRED,
GLUONUTIL_INTERFACE_TYPE_WIRELESS,
GLUONUTIL_INTERFACE_TYPE_TUNNEL,
};
void gluonutil_get_interface_lower(char out[IF_NAMESIZE], const char *ifname);
char * gluonutil_get_interface_address(const char *ifname);
enum gluonutil_interface_type gluonutil_get_interface_type(const char *ifname);
bool gluonutil_get_node_prefix6(struct in6_addr *prefix);
struct json_object * gluonutil_wrap_string(const char *str);
......@@ -42,6 +32,7 @@ struct json_object * gluonutil_wrap_and_free_string(char *str);
bool gluonutil_has_domains(void);
char * gluonutil_get_domain(void);
char * gluonutil_get_primary_domain(void);
struct json_object * gluonutil_load_site_config(void);
#endif /* _LIBGLUON_LIBGLUON_H_ */
......@@ -4,10 +4,10 @@ Subject: procd: add support for alternative rc.d directories
diff --git a/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch b/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch
new file mode 100644
index 0000000000000000000000000000000000000000..bc2434200364b46f1db4c2eec22c4e8b973844d5
index 0000000000000000000000000000000000000000..16d3179f05c64b7178f883745294c64a27127775
--- /dev/null
+++ b/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch
@@ -0,0 +1,97 @@
@@ -0,0 +1,80 @@
+From 03a2bc70e4260ec9f669391c47b9a7a9ecd0b75d Mon Sep 17 00:00:00 2001
+Message-Id: <03a2bc70e4260ec9f669391c47b9a7a9ecd0b75d.1407329621.git.mschiffer@universe-factory.net>
+From: Matthias Schiffer <mschiffer@universe-factory.net>
......@@ -19,21 +19,10 @@ index 0000000000000000000000000000000000000000..bc2434200364b46f1db4c2eec22c4e8b
+ rcS.c | 2 +-
+ 2 files changed, 39 insertions(+), 1 deletion(-)
+
+diff --git a/initd/preinit.c b/initd/preinit.c
+index fb94527..8b832a7 100644
+--- a/initd/preinit.c
++++ b/initd/preinit.c
+@@ -12,6 +12,8 @@
+ * GNU General Public License for more details.
+ */
+
++#define _GNU_SOURCE
++
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/mount.h>
+@@ -46,6 +48,35 @@ check_dbglvl(void)
+ debug = lvl;
+@@ -87,12 +87,42 @@ fail:
+ free(command);
+ }
+
++static char*
......@@ -68,15 +57,14 @@ index 0000000000000000000000000000000000000000..bc2434200364b46f1db4c2eec22c4e8b
+ static void
+ spawn_procd(struct uloop_process *proc, int ret)
+ {
+@@ -53,6 +84,7 @@ spawn_procd(struct uloop_process *proc, int ret)
+ char *wdt_fd = watchdog_fd();
+ char *argv[] = { "/sbin/procd", NULL};
+ struct stat s;
+ char dbg[2];
++ char *rc_d_path;
+
+ if (plugd_proc.pid > 0)
+ kill(plugd_proc.pid, SIGKILL);
+@@ -72,6 +104,12 @@ spawn_procd(struct uloop_process *proc, int ret)
+@@ -112,6 +142,12 @@ spawn_procd(struct uloop_process *proc,
+ setenv("DBGLVL", dbg, 1);
+ }
+
......@@ -89,11 +77,9 @@ index 0000000000000000000000000000000000000000..bc2434200364b46f1db4c2eec22c4e8b
+ execvp(argv[0], argv);
+ }
+
+diff --git a/rcS.c b/rcS.c
+index 0e1b0ba..1b00831 100644
+--- a/rcS.c
++++ b/rcS.c
+@@ -150,7 +150,7 @@ int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *))
+@@ -184,7 +184,7 @@ int rcS(char *pattern, char *param, void
+ q.empty_cb = q_empty;
+ q.max_running_tasks = 1;
+
......@@ -102,6 +88,3 @@ index 0000000000000000000000000000000000000000..bc2434200364b46f1db4c2eec22c4e8b
+ }
+
+ int rc(const char *file, char *param)
+--
+2.0.4
+