diff options
author | Darren Tucker <dtucker@zip.com.au> | 2009-07-06 07:11:13 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2009-07-06 07:11:13 +1000 |
commit | e841eb065426d9c9c9e107e76d816107d68554a7 (patch) | |
tree | bf7e3d7b01898caa4df508849bc7d16eb4c7103e /packet.c | |
parent | 821d3dbe36faa1e53a269e434487d0617a0a1578 (diff) |
- andreas@cvs.openbsd.org 2009/06/27 09:29:06
[packet.h packet.c]
packet_bacup_state() and packet_restore_state() will be used to
temporarily save the current state ren resuming a suspended connection.
ok markus@
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 51 |
1 files changed, 49 insertions, 2 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.c,v 1.165 2009/06/12 20:58:32 andreas Exp $ */ | 1 | /* $OpenBSD: packet.c,v 1.166 2009/06/27 09:29:06 andreas Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -194,7 +194,7 @@ struct session_state { | |||
194 | TAILQ_HEAD(, packet) outgoing; | 194 | TAILQ_HEAD(, packet) outgoing; |
195 | }; | 195 | }; |
196 | 196 | ||
197 | static struct session_state *active_state; | 197 | static struct session_state *active_state, *backup_state; |
198 | 198 | ||
199 | static struct session_state * | 199 | static struct session_state * |
200 | alloc_session_state(void) | 200 | alloc_session_state(void) |
@@ -1887,3 +1887,50 @@ packet_get_newkeys(int mode) | |||
1887 | { | 1887 | { |
1888 | return (void *)active_state->newkeys[mode]; | 1888 | return (void *)active_state->newkeys[mode]; |
1889 | } | 1889 | } |
1890 | |||
1891 | /* | ||
1892 | * Save the state for the real connection, and use a separate state when | ||
1893 | * resuming a suspended connection. | ||
1894 | */ | ||
1895 | void | ||
1896 | packet_backup_state(void) | ||
1897 | { | ||
1898 | struct session_state *tmp; | ||
1899 | |||
1900 | close(active_state->connection_in); | ||
1901 | active_state->connection_in = -1; | ||
1902 | close(active_state->connection_out); | ||
1903 | active_state->connection_out = -1; | ||
1904 | if (backup_state) | ||
1905 | tmp = backup_state; | ||
1906 | else | ||
1907 | tmp = alloc_session_state(); | ||
1908 | backup_state = active_state; | ||
1909 | active_state = tmp; | ||
1910 | } | ||
1911 | |||
1912 | /* | ||
1913 | * Swap in the old state when resuming a connecion. | ||
1914 | */ | ||
1915 | void | ||
1916 | packet_restore_state(void) | ||
1917 | { | ||
1918 | struct session_state *tmp; | ||
1919 | void *buf; | ||
1920 | u_int len; | ||
1921 | |||
1922 | tmp = backup_state; | ||
1923 | backup_state = active_state; | ||
1924 | active_state = tmp; | ||
1925 | active_state->connection_in = backup_state->connection_in; | ||
1926 | backup_state->connection_in = -1; | ||
1927 | active_state->connection_out = backup_state->connection_out; | ||
1928 | backup_state->connection_out = -1; | ||
1929 | len = buffer_len(&backup_state->input); | ||
1930 | if (len > 0) { | ||
1931 | buf = buffer_ptr(&backup_state->input); | ||
1932 | buffer_append(&active_state->input, buf, len); | ||
1933 | buffer_clear(&backup_state->input); | ||
1934 | add_recv_bytes(len); | ||
1935 | } | ||
1936 | } | ||