msgb: msgb_get() is supposed to get bytes from END, msgb_pull() from HEAD

msgb_get() has been wrong all the time, despite the documentation being
correct.  If you've used the broken msgb_get() before, you have to
change your code now, sorry.
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 5457a07..36c7c0f 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -72,6 +72,7 @@
 extern void msgb_enqueue(struct llist_head *queue, struct msgb *msg);
 extern struct msgb *msgb_dequeue(struct llist_head *queue);
 extern void msgb_reset(struct msgb *m);
+uint16_t msgb_length(const struct msgb *msg);
 
 #ifdef MSGB_DEBUG
 #include <osmocom/core/panic.h>
@@ -226,8 +227,11 @@
  */
 static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len)
 {
-	unsigned char *tmp = msgb->data;
-	msgb->data += len;
+	unsigned char *tmp = msgb->data - len;
+	if (msgb_length(msgb) < len)
+		MSGB_ABORT(msgb, "msgb too small to get %u (len %u)\n",
+			   len, msgb_length(msgb));
+	msgb->tail -= len;
 	msgb->len -= len;
 	return tmp;
 }
@@ -295,6 +299,34 @@
 	return msgb->data += len;
 }
 
+/*! \brief remove uint8 from front of message
+ *  \param[in] msgb message buffer
+ *  \returns 8bit value taken from end of msgb
+ */
+static inline uint8_t msgb_pull_u8(struct msgb *msgb)
+{
+	uint8_t *space = msgb_pull(msgb, 1);
+	return space[0];
+}
+/*! \brief remove uint16 from front of message
+ *  \param[in] msgb message buffer
+ *  \returns 16bit value taken from end of msgb
+ */
+static inline uint16_t msgb_pull_u16(struct msgb *msgb)
+{
+	uint8_t *space = msgb_pull(msgb, 2);
+	return space[0] << 8 | space[1];
+}
+/*! \brief remove uint32 from front of message
+ *  \param[in] msgb message buffer
+ *  \returns 32bit value taken from end of msgb
+ */
+static inline uint32_t msgb_pull_u32(struct msgb *msgb)
+{
+	uint8_t *space = msgb_pull(msgb, 4);
+	return space[0] << 24 | space[1] << 16 | space[2] << 8 | space[3];
+}
+
 /*! \brief Increase headroom of empty msgb, reducing the tailroom
  *  \param[in] msg message buffer
  *  \param[in] len amount of extra octets to be reserved as headroom
@@ -362,7 +394,6 @@
 /* non inline functions to ease binding */
 
 uint8_t *msgb_data(const struct msgb *msg);
-uint16_t msgb_length(const struct msgb *msg);
 void msgb_set_talloc_ctx(void *ctx);
 
 /*! @} */