/** * struct msgbuf - Buffer struct to construct SSH messages. * @begin: Pointer to the beginning of the allocated buffer space. * @end: Pointer to the end (one past last element) of the allocated buffer * space. * @ptr: Pointer to the first free element in the buffer.
*/ struct msgbuf {
u8 *begin;
u8 *end;
u8 *ptr;
};
/** * msgb_init() - Initialize the given message buffer struct. * @msgb: The buffer struct to initialize * @ptr: Pointer to the underlying memory by which the buffer will be backed. * @cap: Size of the underlying memory. * * Initialize the given message buffer struct using the provided memory as * backing.
*/ staticinlinevoid msgb_init(struct msgbuf *msgb, u8 *ptr, size_t cap)
{
msgb->begin = ptr;
msgb->end = ptr + cap;
msgb->ptr = ptr;
}
/** * msgb_bytes_used() - Return the current number of bytes used in the buffer. * @msgb: The message buffer.
*/ staticinline size_t msgb_bytes_used(conststruct msgbuf *msgb)
{ return msgb->ptr - msgb->begin;
}
/** * msgb_push_u16() - Push a u16 value to the buffer. * @msgb: The message buffer. * @value: The value to push to the buffer.
*/ staticinlinevoid msgb_push_u16(struct msgbuf *msgb, u16 value)
{ if (WARN_ON(msgb->ptr + sizeof(u16) > msgb->end)) return;
__msgb_push_u16(msgb, value);
}
/** * msgb_push_syn() - Push SSH SYN bytes to the buffer. * @msgb: The message buffer.
*/ staticinlinevoid msgb_push_syn(struct msgbuf *msgb)
{
msgb_push_u16(msgb, SSH_MSG_SYN);
}
/** * msgb_push_buf() - Push raw data to the buffer. * @msgb: The message buffer. * @buf: The data to push to the buffer. * @len: The length of the data to push to the buffer.
*/ staticinlinevoid msgb_push_buf(struct msgbuf *msgb, const u8 *buf, size_t len)
{
msgb->ptr = memcpy(msgb->ptr, buf, len) + len;
}
/** * msgb_push_crc() - Compute CRC and push it to the buffer. * @msgb: The message buffer. * @buf: The data for which the CRC should be computed. * @len: The length of the data for which the CRC should be computed.
*/ staticinlinevoid msgb_push_crc(struct msgbuf *msgb, const u8 *buf, size_t len)
{
msgb_push_u16(msgb, ssh_crc(buf, len));
}
/** * msgb_push_frame() - Push a SSH message frame header to the buffer. * @msgb: The message buffer * @ty: The type of the frame. * @len: The length of the payload of the frame. * @seq: The sequence ID of the frame/packet.
*/ staticinlinevoid msgb_push_frame(struct msgbuf *msgb, u8 ty, u16 len, u8 seq)
{
u8 *const begin = msgb->ptr;
if (WARN_ON(msgb->ptr + sizeof(struct ssh_frame) > msgb->end)) return;
/** * msgb_push_ack() - Push a SSH ACK frame to the buffer. * @msgb: The message buffer * @seq: The sequence ID of the frame/packet to be ACKed.
*/ staticinlinevoid msgb_push_ack(struct msgbuf *msgb, u8 seq)
{ /* SYN. */
msgb_push_syn(msgb);
/* Payload CRC (ACK-type frames do not have a payload). */
msgb_push_crc(msgb, msgb->ptr, 0);
}
/** * msgb_push_cmd() - Push a SSH command frame with payload to the buffer. * @msgb: The message buffer. * @seq: The sequence ID (SEQ) of the frame/packet. * @rqid: The request ID (RQID) of the request contained in the frame. * @rqst: The request to wrap in the frame.
*/ staticinlinevoid msgb_push_cmd(struct msgbuf *msgb, u8 seq, u16 rqid, conststruct ssam_request *rqst)
{ const u8 type = SSH_FRAME_TYPE_DATA_SEQ;
u8 *cmd;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.