增加ipv6辅助信息的返回
This commit is contained in:
parent
88a2d5281e
commit
0dd32a5410
@ -56,7 +56,6 @@
|
|||||||
pending_commands = #{},
|
pending_commands = #{},
|
||||||
|
|
||||||
ping_counter = 0,
|
ping_counter = 0,
|
||||||
ipv6_assist = undefined,
|
|
||||||
|
|
||||||
%% 离线回调函数
|
%% 离线回调函数
|
||||||
offline_cb :: undefined | fun()
|
offline_cb :: undefined | fun()
|
||||||
@ -101,8 +100,7 @@ start_link(Conn, Limits) when is_list(Limits) ->
|
|||||||
init([Conn, Limits]) ->
|
init([Conn, Limits]) ->
|
||||||
MaxPacketSize = proplists:get_value(max_packet_size, Limits, 16384),
|
MaxPacketSize = proplists:get_value(max_packet_size, Limits, 16384),
|
||||||
HeartbeatSec = proplists:get_value(heartbeat_sec, Limits, 10),
|
HeartbeatSec = proplists:get_value(heartbeat_sec, Limits, 10),
|
||||||
Ipv6Assist = ipv6_assist_info(),
|
{ok, initializing, #state{conn = Conn, max_packet_size = MaxPacketSize, heartbeat_sec = HeartbeatSec}, [{next_event, internal, do_init}]}.
|
||||||
{ok, initializing, #state{conn = Conn, max_packet_size = MaxPacketSize, heartbeat_sec = HeartbeatSec, ipv6_assist = Ipv6Assist}, [{next_event, internal, do_init}]}.
|
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc This function is called by a gen_statem when it needs to find out
|
%% @doc This function is called by a gen_statem when it needs to find out
|
||||||
@ -125,8 +123,17 @@ handle_event(info, {quic, dgram_state_changed, Conn, Opts = #{dgram_send_enabled
|
|||||||
logger:debug("[sdlan_quic_channel] dgram_state_changed, opts: ~p", [Opts]),
|
logger:debug("[sdlan_quic_channel] dgram_state_changed, opts: ~p", [Opts]),
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
|
|
||||||
handle_event(info, {quic, new_stream, Stream, Opts}, waiting_stream, State=#state{max_packet_size = MaxPacketSize, heartbeat_sec = HeartbeatSec, ipv6_assist = Ipv6Assist}) ->
|
handle_event(info, {quic, new_stream, Stream, Opts}, waiting_stream, State=#state{max_packet_size = MaxPacketSize, heartbeat_sec = HeartbeatSec}) ->
|
||||||
logger:debug("[sdlan_quic_channel] call new_stream: ~p, opts: ~p", [Stream, Opts]),
|
logger:debug("[sdlan_quic_channel] call new_stream: ~p, opts: ~p", [Stream, Opts]),
|
||||||
|
Ipv6Assist = case application:get_env(sdlan, ipv6_assist_info) of
|
||||||
|
{ok, {V6Bytes, Port}} ->
|
||||||
|
#'SDLV6Info' {
|
||||||
|
v6 = V6Bytes,
|
||||||
|
port = Port
|
||||||
|
};
|
||||||
|
_ ->
|
||||||
|
undefined
|
||||||
|
end,
|
||||||
%% 发送欢迎消息
|
%% 发送欢迎消息
|
||||||
WelcomePkt = sdlan_pb:encode_msg(#'SDLWelcome'{
|
WelcomePkt = sdlan_pb:encode_msg(#'SDLWelcome'{
|
||||||
version = 1,
|
version = 1,
|
||||||
@ -432,19 +439,3 @@ get_rules(SrcIdentityId, DstIdentityId) when is_integer(SrcIdentityId), is_integ
|
|||||||
SrcPolicyIds = identity_policy_ets:get_policies(SrcIdentityId),
|
SrcPolicyIds = identity_policy_ets:get_policies(SrcIdentityId),
|
||||||
DstPolicyIds = identity_policy_ets:get_policies(DstIdentityId),
|
DstPolicyIds = identity_policy_ets:get_policies(DstIdentityId),
|
||||||
rule_ets:get_rules(SrcPolicyIds, DstPolicyIds).
|
rule_ets:get_rules(SrcPolicyIds, DstPolicyIds).
|
||||||
|
|
||||||
-spec ipv6_assist_info() -> undefined | #'SDLV6Info'{}.
|
|
||||||
ipv6_assist_info() ->
|
|
||||||
case application:get_env(sdlan, ipv6_assist) of
|
|
||||||
{ok, Props} ->
|
|
||||||
Port = proplists:get_value(port, Props, 0),
|
|
||||||
GlobalAddr6 = proplists:get_value(global_addr6, Props, <<"">>),
|
|
||||||
case {Port, sdlan_util:ipv6_to_bytes(GlobalAddr6)} of
|
|
||||||
{Port0, V6Bytes = <<_:128>>} when is_integer(Port0), Port0 > 0 ->
|
|
||||||
#'SDLV6Info'{port = Port0, v6 = V6Bytes};
|
|
||||||
_ ->
|
|
||||||
undefined
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
undefined
|
|
||||||
end.
|
|
||||||
|
|||||||
@ -14,6 +14,14 @@ start(_StartType, _StartArgs) ->
|
|||||||
%% 加速内存的回收
|
%% 加速内存的回收
|
||||||
erlang:system_flag(fullsweep_after, 16),
|
erlang:system_flag(fullsweep_after, 16),
|
||||||
|
|
||||||
|
%% 设置环境变量
|
||||||
|
case sdlan_util:ipv6_assist_info() of
|
||||||
|
{ok, V6Info} ->
|
||||||
|
application:set_env(sdlan, ipv6_assist_info, V6Info);
|
||||||
|
undefined ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
|
||||||
%% 启动注册表
|
%% 启动注册表
|
||||||
sdlan_hostname_regedit:init(),
|
sdlan_hostname_regedit:init(),
|
||||||
sdlan_domain_regedit:init(),
|
sdlan_domain_regedit:init(),
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
-export([json_data/1, json_error/2]).
|
-export([json_data/1, json_error/2]).
|
||||||
-export([is_broadcast_mac/1, is_multicast_mac/1]).
|
-export([is_broadcast_mac/1, is_multicast_mac/1]).
|
||||||
-export([ipv4_to_int/1, int_to_ipv4/1, ips/2, format_ip/1]).
|
-export([ipv4_to_int/1, int_to_ipv4/1, ips/2, format_ip/1]).
|
||||||
-export([ipv6_to_bytes/1, ipv6_bytes_to_binary/1]).
|
-export([ipv6_to_bytes/1, ipv6_bytes_to_binary/1, ipv6_assist_info/0]).
|
||||||
-export([hmac/2]).
|
-export([hmac/2]).
|
||||||
|
|
||||||
-spec format_mac(Mac :: binary()) -> binary().
|
-spec format_mac(Mac :: binary()) -> binary().
|
||||||
@ -141,6 +141,22 @@ ipv6_bytes_to_binary(<<A:16, B:16, C:16, D:16, E:16, F:16, G:16, H:16>>) ->
|
|||||||
ipv6_bytes_to_binary(_) ->
|
ipv6_bytes_to_binary(_) ->
|
||||||
<<"">>.
|
<<"">>.
|
||||||
|
|
||||||
|
-spec ipv6_assist_info() -> undefined | {ok, {binary(), integer()}}.
|
||||||
|
ipv6_assist_info() ->
|
||||||
|
case application:get_env(sdlan, ipv6_assist) of
|
||||||
|
{ok, Props} ->
|
||||||
|
Port = proplists:get_value(port, Props, 0),
|
||||||
|
GlobalAddr6 = proplists:get_value(global_addr6, Props, <<"">>),
|
||||||
|
case {Port, ipv6_to_bytes(GlobalAddr6)} of
|
||||||
|
{Port0, V6Bytes = <<_:128>>} when is_integer(Port0), Port0 > 0 ->
|
||||||
|
{ok, {V6Bytes, Port0}};
|
||||||
|
_ ->
|
||||||
|
undefined
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
undefined
|
||||||
|
end.
|
||||||
|
|
||||||
-spec hmac(Key :: binary(), Data :: binary()) -> string().
|
-spec hmac(Key :: binary(), Data :: binary()) -> string().
|
||||||
hmac(Key, Data) when is_binary(Key), is_binary(Data) ->
|
hmac(Key, Data) when is_binary(Key), is_binary(Data) ->
|
||||||
Digest = crypto:mac(hmac, md5, Key, Data),
|
Digest = crypto:mac(hmac, md5, Key, Data),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user