17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Author: Tatu Ylonen <ylo@cs.hut.fi> 37c478bd9Sstevel@tonic-gate * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 47c478bd9Sstevel@tonic-gate * All rights reserved 57c478bd9Sstevel@tonic-gate * Interface for the packet protocol functions. 67c478bd9Sstevel@tonic-gate * 77c478bd9Sstevel@tonic-gate * As far as I am concerned, the code I have written for this software 87c478bd9Sstevel@tonic-gate * can be used freely for any purpose. Any derived versions of this 97c478bd9Sstevel@tonic-gate * software must be clearly marked as such, and if the derived work is 107c478bd9Sstevel@tonic-gate * incompatible with the protocol description in the RFC file, it must be 117c478bd9Sstevel@tonic-gate * called by a name other than "ssh" or "Secure Shell". 127c478bd9Sstevel@tonic-gate */ 137c478bd9Sstevel@tonic-gate /* 14*6f786aceSNobutomo Nakano * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 157c478bd9Sstevel@tonic-gate * Use is subject to license terms. 167c478bd9Sstevel@tonic-gate */ 177c478bd9Sstevel@tonic-gate 189a8058b5Sjp161948 #ifndef _PACKET_H 199a8058b5Sjp161948 #define _PACKET_H 209a8058b5Sjp161948 219a8058b5Sjp161948 /* $OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $ */ 229a8058b5Sjp161948 239a8058b5Sjp161948 #ifdef __cplusplus 249a8058b5Sjp161948 extern "C" { 259a8058b5Sjp161948 #endif 269a8058b5Sjp161948 279a8058b5Sjp161948 287c478bd9Sstevel@tonic-gate #include <openssl/bn.h> 299a8058b5Sjp161948 #include "kex.h" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef ALTPRIVSEP 327c478bd9Sstevel@tonic-gate /* Monitor-side functions */ 337c478bd9Sstevel@tonic-gate void packet_set_server(void); 347c478bd9Sstevel@tonic-gate void packet_set_no_monitor(void); 357c478bd9Sstevel@tonic-gate void packet_set_monitor(int pip_fd); 367c478bd9Sstevel@tonic-gate int packet_is_server(void); 377c478bd9Sstevel@tonic-gate int packet_is_monitor(void); 387c478bd9Sstevel@tonic-gate void packet_set_packet(const void *buf, u_int len); 39cd7d5fafSJan Pechanec void packet_set_fds(int fd, int restore); 407c478bd9Sstevel@tonic-gate #endif /* ALTPRIVSEP */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate void packet_set_connection(int, int); 437c478bd9Sstevel@tonic-gate void packet_set_nonblocking(void); 447c478bd9Sstevel@tonic-gate int packet_get_connection_in(void); 457c478bd9Sstevel@tonic-gate int packet_get_connection_out(void); 467c478bd9Sstevel@tonic-gate void packet_close(void); 477c478bd9Sstevel@tonic-gate void packet_set_encryption_key(const u_char *, u_int, int); 487c478bd9Sstevel@tonic-gate u_int packet_get_encryption_key(u_char *); 497c478bd9Sstevel@tonic-gate void packet_set_protocol_flags(u_int); 507c478bd9Sstevel@tonic-gate u_int packet_get_protocol_flags(void); 517c478bd9Sstevel@tonic-gate void packet_start_compression(int); 527c478bd9Sstevel@tonic-gate void packet_set_interactive(int); 537c478bd9Sstevel@tonic-gate int packet_is_interactive(void); 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate void packet_start(u_char); 567c478bd9Sstevel@tonic-gate void packet_put_char(int ch); 577c478bd9Sstevel@tonic-gate void packet_put_int(u_int value); 587c478bd9Sstevel@tonic-gate void packet_put_bignum(BIGNUM * value); 597c478bd9Sstevel@tonic-gate void packet_put_bignum2(BIGNUM * value); 607c478bd9Sstevel@tonic-gate void packet_put_string(const void *buf, u_int len); 617c478bd9Sstevel@tonic-gate void packet_put_cstring(const char *str); 627c478bd9Sstevel@tonic-gate void packet_put_raw(const void *buf, u_int len); 637c478bd9Sstevel@tonic-gate void packet_send(void); 647c478bd9Sstevel@tonic-gate 65*6f786aceSNobutomo Nakano void packet_put_utf8_string(const char *str, uint_t len); 66*6f786aceSNobutomo Nakano void packet_put_utf8_cstring(const char *str); 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate int packet_read(void); 697c478bd9Sstevel@tonic-gate void packet_read_expect(int type); 707c478bd9Sstevel@tonic-gate int packet_read_poll(void); 717c478bd9Sstevel@tonic-gate void packet_process_incoming(const char *buf, u_int len); 727c478bd9Sstevel@tonic-gate int packet_read_seqnr(u_int32_t *seqnr_p); 737c478bd9Sstevel@tonic-gate int packet_read_poll_seqnr(u_int32_t *seqnr_p); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate u_int packet_get_char(void); 767c478bd9Sstevel@tonic-gate u_int packet_get_int(void); 777c478bd9Sstevel@tonic-gate void packet_get_bignum(BIGNUM * value); 787c478bd9Sstevel@tonic-gate void packet_get_bignum2(BIGNUM * value); 797c478bd9Sstevel@tonic-gate void *packet_get_raw(u_int *length_ptr); 807c478bd9Sstevel@tonic-gate void *packet_get_string(u_int *length_ptr); 81*6f786aceSNobutomo Nakano char *packet_get_utf8_string(uint_t *length_ptr); 827c478bd9Sstevel@tonic-gate void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); 837c478bd9Sstevel@tonic-gate void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate void set_newkeys(int mode); 869a8058b5Sjp161948 void free_keys(Newkeys *keys); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate void packet_write_poll(void); 897c478bd9Sstevel@tonic-gate void packet_write_wait(void); 907c478bd9Sstevel@tonic-gate int packet_have_data_to_write(void); 917c478bd9Sstevel@tonic-gate int packet_not_very_much_data_to_write(void); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate int packet_connection_is_on_socket(void); 947c478bd9Sstevel@tonic-gate int packet_connection_is_ipv4(void); 957c478bd9Sstevel@tonic-gate int packet_remaining(void); 967c478bd9Sstevel@tonic-gate void packet_send_ignore(int); 977c478bd9Sstevel@tonic-gate void packet_add_padding(u_char); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate void tty_make_modes(int, struct termios *); 1007c478bd9Sstevel@tonic-gate void tty_parse_modes(int, int *); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate extern int max_packet_size; 1037c478bd9Sstevel@tonic-gate int packet_set_maxsize(int); 1047c478bd9Sstevel@tonic-gate #define packet_get_maxsize() max_packet_size 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* don't allow remaining bytes after the end of the message */ 1077c478bd9Sstevel@tonic-gate #define packet_check_eom() \ 1087c478bd9Sstevel@tonic-gate do { \ 1097c478bd9Sstevel@tonic-gate int _len = packet_remaining(); \ 1107c478bd9Sstevel@tonic-gate if (_len > 0) { \ 1117c478bd9Sstevel@tonic-gate log("Packet integrity error (%d bytes remaining) at %s:%d", \ 1127c478bd9Sstevel@tonic-gate _len ,__FILE__, __LINE__); \ 1137c478bd9Sstevel@tonic-gate packet_disconnect("Packet integrity error."); \ 1147c478bd9Sstevel@tonic-gate } \ 1157c478bd9Sstevel@tonic-gate } while (0) 1167c478bd9Sstevel@tonic-gate 1179a8058b5Sjp161948 int packet_need_rekeying(void); 1189a8058b5Sjp161948 void packet_set_rekey_limit(u_int32_t); 1199a8058b5Sjp161948 120cd7d5fafSJan Pechanec /* see a comment attached to will_daemonize in packet.c for more information */ 121cd7d5fafSJan Pechanec #define NOT_DAEMONIZING 0 122cd7d5fafSJan Pechanec #define DAEMONIZING_REQUESTED 1 123cd7d5fafSJan Pechanec #define FIRST_NEWKEYS_PROCESSED 2 124cd7d5fafSJan Pechanec #define SECOND_NEWKEYS_PROCESSED 3 125cd7d5fafSJan Pechanec 1267c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate #endif 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate #endif /* _PACKET_H */ 131