|
1 | 1 | %%-*- mode: erlang -*-
|
2 | 2 | %% emqx_coap config mapping
|
3 |
| -{mapping, "coap.ip", "emqx_coap.ip", [ |
4 |
| - {datatype, string} |
5 |
| -]}. |
6 |
| - |
7 |
| -{mapping, "coap.port", "emqx_coap.port", [ |
8 |
| - {datatype, integer} |
| 3 | +{mapping, "coap.bind.udp.$number", "emqx_coap.bind_udp", [ |
| 4 | + {datatype, ip}, |
| 5 | + {default, "0.0.0.0:5683"} |
9 | 6 | ]}.
|
10 | 7 |
|
11 | 8 | {mapping, "coap.enable_stats", "emqx_coap.enable_stats", [
|
12 | 9 | {datatype, flag}
|
13 | 10 | ]}.
|
14 | 11 |
|
15 |
| -{mapping, "coap.dtls.port", "emqx_coap.dtls_opts", [ |
16 |
| - {datatype, integer} |
| 12 | +{mapping, "coap.bind.dtls.$number", "emqx_coap.bind_dtls", [ |
| 13 | + {datatype, ip}, |
| 14 | + {default, "0.0.0.0:5684"} |
17 | 15 | ]}.
|
18 | 16 |
|
19 | 17 | {mapping, "coap.dtls.keyfile", "emqx_coap.dtls_opts", [
|
|
41 | 39 | {datatype, string}
|
42 | 40 | ]}.
|
43 | 41 |
|
| 42 | +{translation, "emqx_coap.bind_udp", fun(Conf) -> |
| 43 | + Options = cuttlefish_variable:filter_by_prefix("coap.bind.udp", Conf), |
| 44 | + lists:map(fun({_, Bind}) -> |
| 45 | + {Ip, Port} = cuttlefish_datatypes:from_string(Bind, ip), |
| 46 | + Opts = case inet:parse_address(Ip) of |
| 47 | + {ok, {_,_,_,_} = Address} -> |
| 48 | + [inet, {ip, Address}]; |
| 49 | + {ok, {_,_,_,_,_,_,_,_} = Address} -> |
| 50 | + [inet6, {ip, Address}] |
| 51 | + end, |
| 52 | + {Port, Opts} |
| 53 | + end, Options) |
| 54 | +end}. |
| 55 | + |
| 56 | +{translation, "emqx_coap.bind_dtls", fun(Conf) -> |
| 57 | + Options = cuttlefish_variable:filter_by_prefix("coap.bind.dtls", Conf), |
| 58 | + lists:map(fun({_, Bind}) -> |
| 59 | + {Ip, Port} = cuttlefish_datatypes:from_string(Bind, ip), |
| 60 | + Opts = case inet:parse_address(Ip) of |
| 61 | + {ok, {_,_,_,_} = Address} -> |
| 62 | + [inet, {ip, Address}]; |
| 63 | + {ok, {_,_,_,_,_,_,_,_} = Address} -> |
| 64 | + [inet6, {ip, Address}] |
| 65 | + end, |
| 66 | + {Port, Opts} |
| 67 | + end, Options) |
| 68 | +end}. |
| 69 | + |
44 | 70 | {translation, "emqx_coap.dtls_opts", fun(Conf) ->
|
45 |
| - case cuttlefish:conf_get("coap.dtls.port", Conf, undefined) of |
46 |
| - undefined -> []; |
47 |
| - Port -> |
48 |
| - Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, |
| 71 | + Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, |
49 | 72 |
|
50 |
| - %% Ciphers |
51 |
| - SplitFun = fun(undefined) -> undefined; (S) -> string:tokens(S, ",") end, |
52 |
| - Ciphers = |
53 |
| - case cuttlefish:conf_get("coap.dtls.ciphers", Conf, undefined) of |
54 |
| - undefined -> |
55 |
| - lists:foldl( |
56 |
| - fun(TlsVer, Ciphers) -> |
57 |
| - Ciphers ++ ssl:cipher_suites(all, TlsVer) |
58 |
| - end, [], ['dtlsv1', 'dtlsv1.2']); |
59 |
| - C -> |
60 |
| - SplitFun(C) |
61 |
| - end, |
| 73 | + %% Ciphers |
| 74 | + SplitFun = fun(undefined) -> undefined; (S) -> string:tokens(S, ",") end, |
| 75 | + Ciphers = |
| 76 | + case cuttlefish:conf_get("coap.dtls.ciphers", Conf, undefined) of |
| 77 | + undefined -> |
| 78 | + lists:foldl( |
| 79 | + fun(TlsVer, Ciphers) -> |
| 80 | + Ciphers ++ ssl:cipher_suites(all, TlsVer) |
| 81 | + end, [], ['dtlsv1', 'dtlsv1.2']); |
| 82 | + C -> |
| 83 | + SplitFun(C) |
| 84 | + end, |
62 | 85 |
|
63 |
| - Filter([{port, Port}, |
64 |
| - {verify, cuttlefish:conf_get("coap.dtls.verify", Conf, undefined)}, |
65 |
| - {keyfile, cuttlefish:conf_get("coap.dtls.keyfile", Conf, undefined)}, |
66 |
| - {certfile, cuttlefish:conf_get("coap.dtls.certfile", Conf, undefined)}, |
67 |
| - {cacertfile, cuttlefish:conf_get("coap.dtls.cacertfile", Conf, undefined)}, |
68 |
| - {fail_if_no_peer_cert, cuttlefish:conf_get("coap.dtls.fail_if_no_peer_cert", Conf, undefined)}, |
69 |
| - {ciphers, Ciphers}]) |
70 |
| - end |
| 86 | + Filter([{verify, cuttlefish:conf_get("coap.dtls.verify", Conf, undefined)}, |
| 87 | + {keyfile, cuttlefish:conf_get("coap.dtls.keyfile", Conf, undefined)}, |
| 88 | + {certfile, cuttlefish:conf_get("coap.dtls.certfile", Conf, undefined)}, |
| 89 | + {cacertfile, cuttlefish:conf_get("coap.dtls.cacertfile", Conf, undefined)}, |
| 90 | + {fail_if_no_peer_cert, cuttlefish:conf_get("coap.dtls.fail_if_no_peer_cert", Conf, undefined)}, |
| 91 | + {ciphers, Ciphers}]) |
71 | 92 | end}.
|
72 | 93 |
|
0 commit comments